本文整理汇总了C#中Microsoft.Build.Construction.ProjectRootElement.AddItem方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectRootElement.AddItem方法的具体用法?C# ProjectRootElement.AddItem怎么用?C# ProjectRootElement.AddItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Construction.ProjectRootElement
的用法示例。
在下文中一共展示了ProjectRootElement.AddItem方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPropertyGroupForSolutionConfiguration
/// <summary>
/// Adds a new property group with contents of the given solution configuration to the project
/// Internal for unit-testing.
/// </summary>
internal static void AddPropertyGroupForSolutionConfiguration(ProjectRootElement msbuildProject, SolutionFile solutionFile, SolutionConfigurationInSolution solutionConfiguration)
{
ProjectPropertyGroupElement solutionConfigurationProperties = msbuildProject.CreatePropertyGroupElement();
msbuildProject.AppendChild(solutionConfigurationProperties);
solutionConfigurationProperties.Condition = GetConditionStringForConfiguration(solutionConfiguration);
StringBuilder solutionConfigurationContents = new StringBuilder(1024);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
using (XmlWriter xw = XmlWriter.Create(solutionConfigurationContents, settings))
{
xw.WriteStartElement("SolutionConfiguration");
// add a project configuration entry for each project in the solution
foreach (ProjectInSolution project in solutionFile.ProjectsInOrder)
{
ProjectConfigurationInSolution projectConfiguration = null;
if (project.ProjectConfigurations.TryGetValue(solutionConfiguration.FullName, out projectConfiguration))
{
xw.WriteStartElement("ProjectConfiguration");
xw.WriteAttributeString("Project", project.ProjectGuid);
xw.WriteAttributeString("AbsolutePath", project.AbsolutePath);
xw.WriteAttributeString("BuildProjectInSolution", projectConfiguration.IncludeInBuild.ToString());
xw.WriteString(projectConfiguration.FullName);
foreach (string dependencyProjectGuid in project.Dependencies)
{
// This is a project that the current project depends *ON* (ie., it must build first)
ProjectInSolution dependencyProject;
if (!solutionFile.ProjectsByGuid.TryGetValue(dependencyProjectGuid, out dependencyProject))
{
// If it's not itself part of the solution, that's an invalid solution
ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(dependencyProject != null, "SubCategoryForSolutionParsingErrors", new BuildEventFileInfo(solutionFile.FullPath), "SolutionParseProjectDepNotFoundError", project.ProjectGuid, dependencyProjectGuid);
}
// Add it to the list of dependencies, but only if it should build in this solution configuration
// (If a project is not selected for build in the solution configuration, it won't build even if it's depended on by something that IS selected for build)
// .. and only if it's known to be MSBuild format, as projects can't use the information otherwise
if (dependencyProject.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat)
{
ProjectConfigurationInSolution dependencyProjectConfiguration = null;
if (dependencyProject.ProjectConfigurations.TryGetValue(solutionConfiguration.FullName, out dependencyProjectConfiguration) &&
WouldProjectBuild(solutionFile, solutionConfiguration.FullName, dependencyProject, dependencyProjectConfiguration))
{
xw.WriteStartElement("ProjectDependency");
xw.WriteAttributeString("Project", dependencyProjectGuid);
xw.WriteEndElement();
}
}
}
xw.WriteEndElement(); // </ProjectConfiguration>
}
}
xw.WriteEndElement(); // </SolutionConfiguration>
}
var escapedSolutionConfigurationContents = EscapingUtilities.Escape(solutionConfigurationContents.ToString());
solutionConfigurationProperties.AddProperty("CurrentSolutionConfigurationContents", escapedSolutionConfigurationContents);
msbuildProject.AddItem(
"SolutionConfiguration",
solutionConfiguration.FullName,
new Dictionary<string, string>
{
{ "Configuration", solutionConfiguration.ConfigurationName },
{ "Platform", solutionConfiguration.PlatformName },
{ "Content", escapedSolutionConfigurationContents },
});
}
示例2: AddVirtualEnvironment
private static ProjectItemElement AddVirtualEnvironment(
ProjectRootElement project,
string sourcePath,
InterpreterFactoryCreationOptions options
) {
var prefixPath = options.PrefixPath ?? string.Empty;
var interpreterPath = string.IsNullOrEmpty(options.InterpreterPath) ?
string.Empty :
CommonUtils.GetRelativeFilePath(prefixPath, options.InterpreterPath);
var windowInterpreterPath = string.IsNullOrEmpty(options.WindowInterpreterPath) ?
string.Empty :
CommonUtils.GetRelativeFilePath(prefixPath, options.WindowInterpreterPath);
var libraryPath = string.IsNullOrEmpty(options.LibraryPath) ?
string.Empty :
CommonUtils.GetRelativeDirectoryPath(prefixPath, options.LibraryPath);
prefixPath = CommonUtils.GetRelativeDirectoryPath(sourcePath, prefixPath);
return project.AddItem(
MSBuildProjectInterpreterFactoryProvider.InterpreterItem,
prefixPath,
new Dictionary<string, string> {
{ MSBuildProjectInterpreterFactoryProvider.IdKey, Guid.NewGuid().ToString("B") },
{ MSBuildProjectInterpreterFactoryProvider.DescriptionKey, options.Description },
{ MSBuildProjectInterpreterFactoryProvider.BaseInterpreterKey, options.IdString },
{ MSBuildProjectInterpreterFactoryProvider.InterpreterPathKey, interpreterPath },
{ MSBuildProjectInterpreterFactoryProvider.WindowsPathKey, windowInterpreterPath },
{ MSBuildProjectInterpreterFactoryProvider.LibraryPathKey, libraryPath },
{ MSBuildProjectInterpreterFactoryProvider.VersionKey, options.LanguageVersionString },
{ MSBuildProjectInterpreterFactoryProvider.ArchitectureKey, options.ArchitectureString },
{ MSBuildProjectInterpreterFactoryProvider.PathEnvVarKey, options.PathEnvironmentVariableName }
}
);
}
示例3: AddAnalysisSetting
private static void AddAnalysisSetting(string name, string value, ProjectRootElement project)
{
ProjectItemElement element = project.AddItem(BuildTaskConstants.SettingItemName, name);
element.AddMetadata(BuildTaskConstants.SettingValueMetadataName, value);
}
示例4: AddVirtualEnvironment
private static ProjectItemElement AddVirtualEnvironment(
ProjectRootElement project,
string sourcePath,
InterpreterConfiguration config
) {
var prefixPath = config.PrefixPath ?? string.Empty;
var interpreterPath = string.IsNullOrEmpty(config.InterpreterPath) ?
string.Empty :
PathUtils.GetRelativeFilePath(prefixPath, config.InterpreterPath);
var windowInterpreterPath = string.IsNullOrEmpty(config.WindowsInterpreterPath) ?
string.Empty :
PathUtils.GetRelativeFilePath(prefixPath, config.WindowsInterpreterPath);
prefixPath = PathUtils.GetRelativeDirectoryPath(sourcePath, prefixPath);
return project.AddItem(
MSBuildConstants.InterpreterItem,
prefixPath,
new Dictionary<string, string> {
{ MSBuildConstants.IdKey, Path.GetFileName(sourcePath) },
{ MSBuildConstants.DescriptionKey, config.Description },
{ MSBuildConstants.BaseInterpreterKey, config.Id },
{ MSBuildConstants.InterpreterPathKey, interpreterPath },
{ MSBuildConstants.WindowsPathKey, windowInterpreterPath },
{ MSBuildConstants.VersionKey, config.Version.ToString() },
{ MSBuildConstants.ArchitectureKey, config.Architecture.ToString("X") },
{ MSBuildConstants.PathEnvVarKey, config.PathEnvironmentVariable }
}
);
}
示例5: GenerateReferences
private void GenerateReferences(ProjectRootElement project, MB.Project projectManipulator, CscTask task, GenerateMsBuildTask generator)
{
projectManipulator.RemoveItems(projectManipulator.GetItemsIgnoringCondition("Reference"));
projectManipulator.RemoveItems(projectManipulator.GetItemsIgnoringCondition("ProjectReference"));
foreach(var reference in task.References.FileNames)
{
var name = Path.GetFileNameWithoutExtension(reference);
var relativeReference = new FileInfo(reference).GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath));
var matchedProject = generator.FindProjectReference(relativeReference);
if (matchedProject == null)
{
project.AddItem(
"Reference",
name,
new[]
{
new KeyValuePair<string, string>("Name", name),
new KeyValuePair<string, string>("HintPath", MB.ProjectCollection.Escape(relativeReference))
});
}
else
{
project.AddItem(
"ProjectReference",
MB.ProjectCollection.Escape(new FileInfo(matchedProject.FullPath).GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath))),
new[]
{
new KeyValuePair<string, string>("Project", matchedProject.GetProjectId().ToString("B")),
new KeyValuePair<string, string>("Name", matchedProject.GetAssemblyName())
});
}
}
foreach (var reference in new[] { "mscorlib", "System", "System.Xml" })
{
project.AddItem("Reference", reference, new[] { new KeyValuePair<string, string>("Name", reference) });
}
}
示例6: GenerateCompileIncludes
private void GenerateCompileIncludes(ProjectRootElement project, MB.Project projectManipulator, CscTask task)
{
projectManipulator.RemoveItems(projectManipulator.GetItemsIgnoringCondition("Compile"));
projectManipulator.RemoveItems(projectManipulator.GetItemsIgnoringCondition("EmbeddedResource"));
foreach (var include in task.Sources.FileNames)
{
project.AddItem(
"Compile",
MB.ProjectCollection.Escape(new FileInfo(include).GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath))),
new[]
{
new KeyValuePair<string, string>("SubType", "Code")
});
}
foreach (var resourceList in task.ResourcesList)
{
foreach (var resource in resourceList.FileNames)
{
project.AddItem(
"EmbeddedResource",
MB.ProjectCollection.Escape(new FileInfo(resource).GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath))),
new[]
{
new KeyValuePair<string, string>("LogicalName", resourceList.GetManifestResourceName(resource))
});
}
}
project.EnsureItemExists("None", MB.ProjectCollection.Escape(
new FileInfo(task.Project.BuildFileLocalName).GetPathRelativeTo(new DirectoryInfo(project.DirectoryPath))));
}
示例7: AddFileToProject
/// <summary>
/// Creates an empty file on disc and adds it to the project as an
/// item with the specified ItemGroup include name.
/// The SonarQubeExclude metadata item is set to the specified value.
/// </summary>
/// <param name="includeName">The name of the item type e.g. Compile, Content</param>
/// <returns>The new project item</returns>
private ProjectItemElement AddFileToProject(ProjectRootElement projectRoot, string includeName)
{
string projectPath = Path.GetDirectoryName(projectRoot.DirectoryPath); // project needs to have been saved for this to work
string fileName = includeName + "_" + System.Guid.NewGuid().ToString();
string fullPath = Path.Combine(projectPath, fileName);
File.WriteAllText(fullPath, "");
ProjectItemElement element = projectRoot.AddItem(includeName, fullPath);
return element;
}
示例8: AddItem
private static ProjectItemElement AddItem(ProjectRootElement projectRoot, string itemTypeName, string include, params string[] idAndValuePairs)
{
ProjectItemElement item = projectRoot.AddItem(itemTypeName, include);
int remainder;
Math.DivRem(idAndValuePairs.Length, 2, out remainder);
Assert.AreEqual(0, remainder, "Test setup error: the supplied list should contain id-location pairs");
for (int index = 0; index < idAndValuePairs.Length; index += 2)
{
item.AddMetadata(idAndValuePairs[index], idAndValuePairs[index + 1]);
}
return item;
}