本文整理汇总了C#中Microsoft.Build.BuildEngine.Project.AddNewItemGroup方法的典型用法代码示例。如果您正苦于以下问题:C# Project.AddNewItemGroup方法的具体用法?C# Project.AddNewItemGroup怎么用?C# Project.AddNewItemGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.BuildEngine.Project
的用法示例。
在下文中一共展示了Project.AddNewItemGroup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: XnaContentProject
public XnaContentProject(Task task, string msBuildPath, string xnaInstallPath)
{
m_engine = new Engine(msBuildPath);
m_engine.RegisterLogger(new XnaContentLogger(task));
m_project = new Project(m_engine);
m_project.AddNewUsingTaskFromAssemblyName("BuildContent", "Microsoft.Xna.Framework.Content.Pipeline, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d");
m_project.AddNewUsingTaskFromAssemblyName("BuildXact", "Microsoft.Xna.Framework.Content.Pipeline, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d");
// Add our Content Pipeline Assemblies
m_pipelineGroup = m_project.AddNewItemGroup();
m_contentGroup = m_project.AddNewItemGroup();
m_contentTarget = m_project.Targets.AddNewTarget("_BuildXNAContentLists");
// Add our Build target
m_xnaTarget = m_project.Targets.AddNewTarget("Build");
m_xnaTarget.DependsOnTargets = "_BuildXNAContentLists";
// Add Default Pipeline Assemblies.
AddPilepineAssembly(xnaInstallPath + "Microsoft.Xna.Framework.Content.Pipeline.EffectImporter.dll");
AddPilepineAssembly(xnaInstallPath + "Microsoft.Xna.Framework.Content.Pipeline.FBXImporter.dll");
AddPilepineAssembly(xnaInstallPath + "Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.dll");
AddPilepineAssembly(xnaInstallPath + "Microsoft.Xna.Framework.Content.Pipeline.XImporter.dll");
}
示例2: Execute
public override bool Execute()
{
bool result = true;
string file = Path.Combine(m_stubsPath, m_name + ".featureproj");
try
{
Project proj = new Project();
proj.DefaultToolsVersion = "3.5";
proj.DefaultTargets = "Build";
BuildPropertyGroup bpg = proj.AddNewPropertyGroup(true);
bpg.AddNewProperty("FeatureName", m_name);
bpg.AddNewProperty("Guid", System.Guid.NewGuid().ToString("B"));
bpg.AddNewProperty("Description", "");
bpg.AddNewProperty("Groups", "");
BuildItemGroup big = proj.AddNewItemGroup();
big.AddNewItem("InteropFeature", Path.GetFileNameWithoutExtension(m_assemblyName).Replace('.', '_'));
big.AddNewItem("DriverLibs", Path.GetFileNameWithoutExtension( m_assemblyName ).Replace( '.', '_' ) + ".$(LIB_EXT)");
big.AddNewItem("MMP_DAT_CreateDatabase", "$(BUILD_TREE_CLIENT)\\pe\\" + m_assemblyName);
big.AddNewItem("RequiredProjects", Path.Combine(m_stubsPath, m_nativeProjectFile));
proj.Save(file);
}
catch(Exception e)
{
Log.LogError("Error trying to create feature project file \"" + file + "\": " + e.Message);
result = false;
}
return result;
}
示例3: GetProjectDependencies
/// <summary>
/// Add a target for a project into the XML doc that's being generated.
/// </summary>
/// <param name="msbuildProject"></param>
/// <param name="solution"></param>
/// <param name="proj"></param>
/// <param name="targetOutputItemName">The name of the item exposing this target's outputs. May be null.</param>
/// <param name="subTargetName"></param>
/// <owner>RGoel, LukaszG</owner>
static private void AddTargetForManagedProject
(
Project msbuildProject,
SolutionParser solution,
ProjectInSolution proj,
string targetOutputItemName,
string subTargetName
)
{
string targetName = ProjectInSolution.DisambiguateProjectTargetName(proj.GetUniqueProjectName());
if (subTargetName != null && subTargetName.Length > 0)
{
targetName = targetName + ":" + subTargetName;
}
Target newTarget = msbuildProject.Targets.AddNewTarget(targetName);
newTarget.DependsOnTargets = GetProjectDependencies(proj.ParentSolution, proj, subTargetName);
newTarget.Condition = "'$(CurrentSolutionConfigurationContents)' != ''";
if (!String.IsNullOrEmpty(targetOutputItemName))
{
newTarget.TargetElement.SetAttribute("Outputs", string.Format(CultureInfo.InvariantCulture, "@({0})", targetOutputItemName));
}
// Only create build items if we're called with the null subtarget. We're getting called
// a total of four times and only want to create the build items once.
bool createBuildItems = (subTargetName == null);
foreach (ConfigurationInSolution solutionConfiguration in solution.SolutionConfigurations)
{
ProjectConfigurationInSolution projectConfiguration = null;
string condition = GetConditionStringForConfiguration(solutionConfiguration);
// Create the build item group for this configuration if we haven't already
if (solutionConfiguration.ProjectBuildItems == null)
{
solutionConfiguration.ProjectBuildItems = msbuildProject.AddNewItemGroup();
solutionConfiguration.ProjectBuildItems.Condition = condition;
}
if (proj.ProjectConfigurations.TryGetValue(solutionConfiguration.FullName, out projectConfiguration))
{
if (projectConfiguration.IncludeInBuild)
{
// We want to specify ToolsVersion on the MSBuild task only if the solution
// is building with a non-Whidbey toolset, because the Whidbey MSBuild task
// does not support the ToolsVersion parameter. If the user explicitly requested
// the 2.0 toolset be used to build the solution while specifying some value
// for the ProjectToolsVersion property, then one of the InitialTargets should
// have produced an error before reaching this point.
// PERF: We could emit two <MSBuild> tasks, with a condition on them. But this doubles the size of
// the solution wrapper project, and the cost is too high. The consequence is that when solution wrapper
// projects are emitted to disk (with MSBUILDEMITSOLUION=1) they cannot be reused for tools version v2.0.
bool specifyProjectToolsVersion =
String.Equals(msbuildProject.ToolsVersion, "2.0", StringComparison.OrdinalIgnoreCase) ? false : true;
BuildTask msbuildTask = AddMSBuildTaskElement(newTarget, proj.RelativePath, subTargetName,
projectConfiguration.ConfigurationName, projectConfiguration.PlatformName, specifyProjectToolsVersion);
msbuildTask.Condition = condition;
if (!String.IsNullOrEmpty(targetOutputItemName))
{
msbuildTask.AddOutputItem("TargetOutputs", targetOutputItemName);
}
if (createBuildItems)
{
string baseItemName = "BuildLevel" + proj.DependencyLevel;
BuildItem projectItem = solutionConfiguration.ProjectBuildItems.AddNewItem(baseItemName, proj.RelativePath, true /* treat as literal */);
projectItem.SetMetadata("Configuration", EscapingUtilities.Escape(projectConfiguration.ConfigurationName));
projectItem.SetMetadata("Platform", EscapingUtilities.Escape(projectConfiguration.PlatformName));
}
}
else
{
BuildTask messageTask = AddErrorWarningMessageElement(newTarget, XMakeElements.message, true, "SolutionProjectSkippedForBuilding", proj.ProjectName, solutionConfiguration.FullName);
messageTask.Condition = condition;
if (createBuildItems)
{
string baseItemName = "SkipLevel" + proj.DependencyLevel;
BuildItem projectItem = solutionConfiguration.ProjectBuildItems.AddNewItem(baseItemName, proj.ProjectName, true /* treat as literal */);
}
}
}
else
{
BuildTask warningTask = AddErrorWarningMessageElement(newTarget, XMakeElements.warning, true, "SolutionProjectConfigurationMissing", proj.ProjectName, solutionConfiguration.FullName);
warningTask.Condition = condition;
//.........这里部分代码省略.........
示例4: AddCacheRelatedProperties
/// <summary>
/// Adds properties indicating the current solution configuration and tools version into the solution project.
/// Also lists all the projects in the solution, as items.
/// </summary>
private static void AddCacheRelatedProperties(Project msbuildProject, string fullSolutionConfigurationName, string toolsVersion, ArrayList projects)
{
BuildPropertyGroup cachePropertyGroup = msbuildProject.AddNewPropertyGroup(false /* insertAtEndOfProject = false */);
// Store the solution configuration, if it's available (ie., not null because it's invalid)
if (fullSolutionConfigurationName != null)
{
cachePropertyGroup.AddNewProperty(cacheSolutionConfigurationPropertyName, fullSolutionConfigurationName);
}
// Store the tools version, too.
cachePropertyGroup.AddNewProperty(cacheToolsVersionPropertyName, toolsVersion);
// And the engine version, so we don't read caches written by other engines.
cachePropertyGroup.AddNewProperty(cacheVersionNumber, Constants.AssemblyVersion);
// And store a list of all the projects. We can use this next time for timestamp checking.
BuildItemGroup cacheItemGroup = msbuildProject.AddNewItemGroup();
foreach (ProjectInSolution project in projects)
{
// Only add projects that correspond to actual files on disk. Solution folders and web projects correspond to folders, so we don't care about them.
if (project.ProjectType != SolutionProjectType.SolutionFolder && project.ProjectType != SolutionProjectType.WebProject)
{
cacheItemGroup.AddNewItem(cacheProjectListName, EscapingUtilities.Escape(project.RelativePath));
}
}
}
示例5: Execute
//.........这里部分代码省略.........
Microsoft.Build.BuildEngine.BuildProperty property = pg.AddNewProperty("Configuration", "Release");
property.Condition = "'$(Configuration)' == ''";
property = pg.AddNewProperty("Platform", "AnyCPU");
property.Condition = "'$(Platform)' == ''";
pg.AddNewProperty("ProductVersion", "10.0.20506");
pg.AddNewProperty("SchemaVersion", "2.0");
pg.AddNewProperty("ProjectGuid", Guid.NewGuid().ToString());
pg.AddNewProperty("OutputType", "Library");
pg.AddNewProperty("AppDesignerFolder", "Properties");
pg.AddNewProperty("RootNamespace", parameters["rimbapi-target-ns"][0]);
pg.AddNewProperty("AssemblyName", parameters["rimbapi-target-ns"][0]);
// Release AnyCPU
pg = project.AddNewPropertyGroup(false);
pg.Condition = "'$(Configuration)|$(Platform)' == 'Release|AnyCPU'";
pg.AddNewProperty("DebugType", "pdbonly");
pg.AddNewProperty("Optimize", "true");
pg.AddNewProperty("OutputPath", "bin\\release");
pg.AddNewProperty("DefineConstants", "TRACE");
pg.AddNewProperty("ErrorReport", "prompt");
pg.AddNewProperty("WarningLevel", "4");
pg.AddNewProperty("DocumentationFile", "bin\\release\\" + parameters["rimbapi-target-ns"][0] + ".xml");
// Create Dir Structure
Directory.CreateDirectory(Path.Combine(hostContext.Output, "bin"));
Directory.CreateDirectory(Path.Combine(hostContext.Output, "lib"));
Directory.CreateDirectory(Path.Combine(hostContext.Output, "Properties"));
Directory.CreateDirectory(Path.Combine(hostContext.Output, "Vocabulary"));
Directory.CreateDirectory(Path.Combine(hostContext.Output, "Interaction"));
// Add reference structure
Microsoft.Build.BuildEngine.BuildItemGroup refItemGroup = project.AddNewItemGroup();
// Add References
File.Copy(Path.Combine(System.Windows.Forms.Application.StartupPath, "MARC.Everest.dll"), Path.Combine(Path.Combine(hostContext.Output, "lib"), "MARC.Everest.dll"), true);
if(makeWP7Proj)
File.Copy(Path.Combine(Path.Combine(System.Windows.Forms.Application.StartupPath, "lib"), "MARC.Everest.Phone.dll"), Path.Combine(Path.Combine(hostContext.Output, "lib"), "MARC.Everest.Phone.dll"), true);
File.Copy(Path.Combine(System.Windows.Forms.Application.StartupPath, "MARC.Everest.xml"), Path.Combine(Path.Combine(hostContext.Output, "lib"), "MARC.Everest.xml"), true);
refItemGroup.AddNewItem("Reference", "System");
refItemGroup.AddNewItem("Reference", "System.Drawing");
refItemGroup.AddNewItem("Reference", "System.Xml");
Microsoft.Build.BuildEngine.BuildItem buildItem = refItemGroup.AddNewItem("Reference", @"MARC.Everest");
buildItem.SetMetadata("SpecificVersion", "false");
buildItem.SetMetadata("HintPath", "lib\\MARC.Everest.dll");
project.AddNewImport("$(MSBuildBinPath)\\Microsoft.CSharp.targets", null);
Microsoft.Build.BuildEngine.BuildItemGroup fileItemGroup = project.AddNewItemGroup(),
phoneFileItemGroup = phoneProj.AddNewItemGroup();
#region Assembly Info
try
{
TextWriter tw = File.CreateText(Path.Combine(Path.Combine(hostContext.Output, "Properties"), "AssemblyInfo.cs"));
try
{
string Header = Template.AssemblyInfo; // Set the header to the default
// Populate template fields
foreach (String[] st in templateFields)
Header = Header.Replace(st[0], st[1]);
示例6: AddNewItem
public override void AddNewItem(Project project, string name, string include)
{
project.AddNewItemGroup().AddNewItem(name, include);
}
示例7: OnResetCsproj
private void OnResetCsproj()
{
String sourceRoot = ConfigurationManager.AppSettings["source_root"];
String csprojName = ConfigurationManager.AppSettings["csproj_name"];
String csprojFile = sourceRoot + csprojName;
Project project = new Project();
project.Load(csprojFile);
BuildItemGroup itemGroup = project.AddNewItemGroup();
itemGroup.AddNewItem("Content", "_static\\data\\okr.me");
itemGroup.AddNewItem("Content", "_static\\data\\cover.png");
itemGroup.AddNewItem("Content", "_static\\data\\okr-bg.png");
itemGroup.AddNewItem("Content", "_static\\data\\okr-icon.png");
itemGroup.AddNewItem("Content", "_static\\data\\okr-splash.png");
itemGroup.AddNewItem("Content", "_static\\data\\okrapp.config");
String[] appFiles = Directory.GetFileSystemEntries(sourceRoot + "_static\\data\\app\\");
foreach (var file in appFiles)
{
itemGroup.AddNewItem("Content", "_static\\data\\app\\" + Path.GetFileName(file));
}
String[] bookFiles = Directory.GetFileSystemEntries(sourceRoot + "_static\\data\\book\\");
foreach (var file in bookFiles)
{
itemGroup.AddNewItem("Content", "_static\\data\\book\\" + Path.GetFileName(file));
}
project.Save(csprojFile);
}
示例8: OnCleanUp
private void OnCleanUp()
{
String sourceRoot = ConfigurationManager.AppSettings["source_root"];
String csprojName = ConfigurationManager.AppSettings["csproj_name"];
String csprojFile = sourceRoot + csprojName;
Project project = new Project();
project.Load(csprojFile);
project.RemoveItemsByName("Content");
// 补上img文件夹
BuildItemGroup itemGroup = project.AddNewItemGroup();
String[] bookFiles = Directory.GetFileSystemEntries(sourceRoot + "_static\\img\\");
foreach (var file in bookFiles)
{
itemGroup.AddNewItem("Content", "_static\\img\\" + Path.GetFileName(file));
}
project.Save(csprojFile);
}
示例9: ICollectionMethodsOnItemPropertyGroupCollection
public void ICollectionMethodsOnItemPropertyGroupCollection()
{
Engine engine = new Engine(@"C:\");
Project project = new Project(engine);
BuildPropertyGroup pg1 = project.AddNewPropertyGroup(true);
BuildPropertyGroup pg2 = project.AddNewPropertyGroup(true);
BuildItemGroup ig1 = project.AddNewItemGroup();
BuildItemGroup ig2 = project.AddNewItemGroup();
BuildPropertyGroup[] pgarray = new BuildPropertyGroup[2];
BuildItemGroup[] igarray = new BuildItemGroup[2];
project.PropertyGroups.CopyTo(pgarray, 0);
project.ItemGroups.CopyTo(igarray, 0);
Assertion.Assert(pgarray[0] == pg1 || pgarray[1] == pg1);
Assertion.Assert(pgarray[0] == pg2 || pgarray[1] == pg2);
Assertion.Assert(igarray[0] == ig1 || igarray[1] == ig1);
Assertion.Assert(igarray[0] == ig2 || igarray[1] == ig2);
}
示例10: ConfigureProject
protected virtual void ConfigureProject(Project proj)
{
_globalProperties = proj.AddNewPropertyGroup(false);
_globalProperties.AddNewProperty("OutputType", "Library");
_globalProperties.AddNewProperty("AssemblyName", AssemblyName);
_globalProperties.AddNewProperty("OutputPath", OutputPath);
_globalProperties.AddNewProperty("Optimize", "true");
_globalProperties.AddNewProperty("NoWarn", "1591,0168");
_globalProperties.AddNewProperty("DocumentationFile", string.Concat(OutputPath, "\\", AssemblyName, ".XML"));
proj.AddNewImport(@"$(MSBuildBinPath)\Microsoft.CSharp.targets", String.Empty);
_references = proj.AddNewItemGroup();
}
示例11: RemoveEvaluatedItemSuccess
public void RemoveEvaluatedItemSuccess()
{
try
{
string includePath = Path.Combine(ObjectModelHelpers.TempProjectDir, "*.foo");
List<string> files = CompatibilityTestHelpers.CreateFiles(4, "foo", "foo", ObjectModelHelpers.TempProjectDir);
Project p = new Project(new Engine());
BuildItemGroup group = p.AddNewItemGroup();
group.AddNewItem("foos", includePath);
object o = p.EvaluatedItems;
files.RemoveAt(files.IndexOf(p.EvaluatedItems[0].FinalItemSpec));
p.RemoveItem(p.EvaluatedItems[0]);
int i = 0;
foreach (string fileName in files)
{
Assertion.AssertEquals(includePath, group[0].FinalItemSpec);
Assertion.AssertEquals(includePath, group[0].Include);
Assertion.AssertEquals(fileName, p.EvaluatedItems[i].Include);
Assertion.AssertEquals(fileName, p.EvaluatedItems[i].FinalItemSpec);
i++;
}
}
finally
{
CompatibilityTestHelpers.CleanupDirectory(ObjectModelHelpers.TempProjectDir);
}
}
示例12: RemoveEvaluatedItem1
public void RemoveEvaluatedItem1()
{
try
{
List<string> files = CompatibilityTestHelpers.CreateFiles(4, "foo", "foo", ObjectModelHelpers.TempProjectDir);
Project p = new Project(new Engine());
BuildItemGroup group = p.AddNewItemGroup();
group.AddNewItem("foos", Path.Combine(ObjectModelHelpers.TempProjectDir, "*.foo"));
object o = p.EvaluatedItems; // this causes the failure
group.RemoveItem(p.EvaluatedItems[0]); // Exception thrown here
Assertion.Fail("success as failure"); // should not get here due to exception above
}
catch (Exception e)
{
if (!(e.GetType().ToString().Contains("InternalErrorException")))
{
Assertion.Fail(e.Message + " was thrown");
}
else
{
Assertion.Assert("InternalErrorException was thrown", true);
}
}
finally
{
CompatibilityTestHelpers.CleanupDirectory(ObjectModelHelpers.TempProjectDir);
}
}
示例13: PrepareProject
/// <summary>
/// Prepares the given MSBuild <see cref="Project"/> with properties and items from the given <see cref="GitHubWebhook"/>.
/// </summary>
/// <param name="project">The project to prepare.</param>
/// <param name="hook">The webhook to prepare the project with.</param>
public static void PrepareProject(Project project, GitHubWebhook hook)
{
BuildPropertyGroup properties = project.AddNewPropertyGroup(false);
properties.AddNewProperty("GitHubAfter", hook.After);
properties.AddNewProperty("GitHubBefore", hook.Before);
properties.AddNewProperty("GitHubRef", hook.Ref);
properties.AddNewProperty("GitHubRepositoryDescription", hook.Repository.Description);
properties.AddNewProperty("GitHubRepositoryForks", hook.Repository.Forks.ToString(CultureInfo.InvariantCulture));
properties.AddNewProperty("GitHubRepositoryHomepage", hook.Repository.Homepage);
properties.AddNewProperty("GitHubRepositoryName", hook.Repository.Name);
properties.AddNewProperty("GitHubRepositoryOwnerName", hook.Repository.Owner.Name);
properties.AddNewProperty("GitHubRepositoryOwnerEmail", hook.Repository.Owner.Email);
properties.AddNewProperty("GitHubRepositoryPlegie", hook.Repository.Plegie);
properties.AddNewProperty("GitHubRepositoryPrivate", hook.Repository.Private.ToString(CultureInfo.InvariantCulture));
properties.AddNewProperty("GitHubRepositoryUrl", hook.Repository.Url);
properties.AddNewProperty("GitHubRepositoryWatchers", hook.Repository.Watchers.ToString(CultureInfo.InvariantCulture));
BuildItemGroup commits = project.AddNewItemGroup();
foreach (GitHubWebhookCommit commit in hook.Commits)
{
BuildItem item = commits.AddNewItem("GitHubCommit", commit.Url);
item.SetMetadata("Id", commit.Id);
item.SetMetadata("Message", commit.Message);
item.SetMetadata("Timestamp", commit.Timestamp);
item.SetMetadata("AuthorName", commit.Author.Name);
item.SetMetadata("AuthorEmail", commit.Author.Email);
}
}
示例14: RemoveItemGroupsWithMatchingCondition
public void RemoveItemGroupsWithMatchingCondition()
{
Project p = new Project();
BuildItemGroup buildItemGroup = p.AddNewItemGroup();
buildItemGroup.Condition = "true";
p.AddNewItemGroup();
Assertion.AssertEquals(2, p.ItemGroups.Count);
p.RemoveItemGroupsWithMatchingCondition("true");
Assertion.AssertEquals(1, p.ItemGroups.Count);
}
示例15: RemoveItemGroup_Imported
public void RemoveItemGroup_Imported()
{
Project p = new Project();
Project i = new Project(p.ParentEngine);
BuildItemGroup buildItemGroup = i.AddNewItemGroup();
p.RemoveItemGroup(buildItemGroup);
}