本文整理汇总了C#中Microsoft.Build.Construction.ProjectRootElement类的典型用法代码示例。如果您正苦于以下问题:C# ProjectRootElement类的具体用法?C# ProjectRootElement怎么用?C# ProjectRootElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProjectRootElement类属于Microsoft.Build.Construction命名空间,在下文中一共展示了ProjectRootElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateInMemoryImport
public async Task CreateInMemoryImport() {
if (_unloadCancellationToken.IsCancellationRequested) {
return;
}
using (var access = await _projectLockService.WriteLockAsync(_unloadCancellationToken)) {
// A bit odd but we have to "check it out" prior to creating it to avoid some of the validations in chk CPS
await access.CheckoutAsync(_inMemoryImportFullPath);
// Now either open or create the in-memory file. Normally Create will happen, but in
// a scenario where your project had previously failed to load for some reason, need to TryOpen
// to avoid a new reason for a project load failure
_inMemoryImport = ProjectRootElement.TryOpen(_inMemoryImportFullPath, access.ProjectCollection);
if (_inMemoryImport != null) {
// The file already exists. Scrape it out so we don’t add duplicate items.
_inMemoryImport.RemoveAllChildren();
} else {
// The project didn’t already exist, so create it, and then mark the evaluated project dirty
// so that MSBuild will notice. This step isn’t necessary if the project was already in memory.
_inMemoryImport = CreateEmptyMsBuildProject(_inMemoryImportFullPath, access.ProjectCollection);
// Note that we actually need to mark every project evaluation dirty that is already loaded.
await ReevaluateLoadedConfiguredProjects(_unloadCancellationToken, access);
}
_filesItemGroup = _inMemoryImport.AddItemGroup();
_directoriesItemGroup = _inMemoryImport.AddItemGroup();
_temporaryAddedItemGroup = _inMemoryImport.AddItemGroup();
}
}
示例2: MSBuildProject
public MSBuildProject(FilePath filePath)
{
FilePath = filePath;
_msBuildProject = ProjectRootElement.Open(filePath.FullPath, _globalCollection);
foreach (var item in _msBuildProject.Items)
{
if (item.ItemType == "Reference")
References.Add(item.Include);
else if (item.ItemType == "Compile" || item.ItemType == "None")
{
var entry = new ProjectFileEntry(new FilePath(this.ProjectDirectory, item.Include));
foreach (var element in item.Metadata)
{
if (element.Name == "DependentUpon")
{
entry.Dependencies.Add(element.Value);
}
}
entry.ParentProject = this;
AddFileEventHandlers(entry);
ProjectFiles.Add(entry);
}
}
SetupEventHandlers();
HasUnsavedData = false;
}
示例3: CreateBuildProject
void CreateBuildProject()
{
string projectPath = Path.Combine(buildDirectory, "content.contentproj");
string outputPath = Path.Combine(buildDirectory, "bin");
// Create the build project.
projectRootElement = ProjectRootElement.Create(projectPath);
// Include the standard targets file that defines how to build XNA Framework content.
projectRootElement.AddImport(Application.StartupPath + "\\Exporters\\FBX\\XNA\\XNA Game Studio\\" +
"v4.0\\Microsoft.Xna.GameStudio.ContentPipeline.targets");
buildProject = new Project(projectRootElement);
buildProject.SetProperty("XnaPlatform", "Windows");
buildProject.SetProperty("XnaProfile", "Reach");
buildProject.SetProperty("XnaFrameworkVersion", "v4.0");
buildProject.SetProperty("Configuration", "Release");
buildProject.SetProperty("OutputPath", outputPath);
buildProject.SetProperty("ContentRootDirectory", ".");
buildProject.SetProperty("ReferencePath", Application.StartupPath);
// Register any custom importers or processors.
foreach (string pipelineAssembly in pipelineAssemblies)
{
buildProject.AddItem("Reference", pipelineAssembly);
}
// Hook up our custom error logger.
errorLogger = new ErrorLogger();
buildParameters = new BuildParameters(ProjectCollection.GlobalProjectCollection)
{Loggers = new ILogger[] {errorLogger}};
}
示例4: BuildAsync
internal static async Task<BuildResult> BuildAsync(this BuildManager buildManager, ITestOutputHelper logger, ProjectCollection projectCollection, ProjectRootElement project, string target, IDictionary<string, string> globalProperties = null, LoggerVerbosity logVerbosity = LoggerVerbosity.Detailed, ILogger[] additionalLoggers = null)
{
Requires.NotNull(buildManager, nameof(buildManager));
Requires.NotNull(projectCollection, nameof(projectCollection));
Requires.NotNull(project, nameof(project));
globalProperties = globalProperties ?? new Dictionary<string, string>();
var projectInstance = new ProjectInstance(project, globalProperties, null, projectCollection);
var brd = new BuildRequestData(projectInstance, new[] { target }, null, BuildRequestDataFlags.ProvideProjectStateAfterBuild);
var parameters = new BuildParameters(projectCollection);
var loggers = new List<ILogger>();
loggers.Add(new ConsoleLogger(logVerbosity, s => logger.WriteLine(s.TrimEnd('\r', '\n')), null, null));
loggers.AddRange(additionalLoggers);
parameters.Loggers = loggers.ToArray();
buildManager.BeginBuild(parameters);
var result = await buildManager.BuildAsync(brd);
buildManager.EndBuild();
return result;
}
示例5: BuildIntegrationTests
public BuildIntegrationTests(ITestOutputHelper logger)
: base(logger)
{
int seed = (int)DateTime.Now.Ticks;
this.random = new Random(seed);
this.Logger.WriteLine("Random seed: {0}", seed);
this.buildManager = new BuildManager();
this.projectCollection = new ProjectCollection();
this.projectDirectory = Path.Combine(this.RepoPath, "projdir");
Directory.CreateDirectory(this.projectDirectory);
this.LoadTargetsIntoProjectCollection();
this.testProject = this.CreateProjectRootElement(this.projectDirectory, "test.proj");
this.testProjectInRoot = this.CreateProjectRootElement(this.RepoPath, "root.proj");
this.globalProperties.Add("NerdbankGitVersioningTasksPath", Environment.CurrentDirectory + "\\");
// Sterilize the test of any environment variables.
foreach (System.Collections.DictionaryEntry variable in Environment.GetEnvironmentVariables())
{
string name = (string)variable.Key;
if (ToxicEnvironmentVariablePrefixes.Any(toxic => name.StartsWith(toxic, StringComparison.OrdinalIgnoreCase)))
{
this.globalProperties[name] = string.Empty;
}
}
}
示例6: ProjectUsingTaskElement
internal ProjectUsingTaskElement (string taskName, string assemblyFile, string assemblyName,
ProjectRootElement containingProject)
{
TaskName = taskName;
AssemblyFile = assemblyFile;
AssemblyName = assemblyName;
ContainingProject = containingProject;
}
示例7: UpgradeProjectCheck
protected override ProjectUpgradeState UpgradeProjectCheck(ProjectRootElement projectXml, ProjectRootElement userProjectXml, Action<__VSUL_ERRORLEVEL, string> log, ref Guid projectFactory, ref __VSPPROJECTUPGRADEVIAFACTORYFLAGS backupSupport) {
var envVarsProp = projectXml.Properties.FirstOrDefault(p => p.Name == NodejsConstants.EnvironmentVariables);
if (envVarsProp != null && !string.IsNullOrEmpty(envVarsProp.Value)) {
return ProjectUpgradeState.OneWayUpgrade;
}
return ProjectUpgradeState.NotNeeded;
}
示例8: ProjectOutputElement
internal ProjectOutputElement (string taskParameter, string itemType, string propertyName,
ProjectRootElement containintProject)
{
TaskParameter = taskParameter;
ItemType = itemType;
PropertyName = propertyName;
ContainingProject = containintProject;
}
示例9: ProjectXmlChangedEventArgs
/// <summary>
/// Initializes a new instance of the <see cref="ProjectXmlChangedEventArgs"/> class
/// that represents a change to a specific project root element.
/// </summary>
/// <param name="projectXml">The ProjectRootElement whose content was actually changed.</param>
/// <param name="unformattedReason">The unformatted (may contain {0}) reason for the dirty event.</param>
/// <param name="formattingParameter">The formatting parameter to use with <paramref name="unformattedReason"/>.</param>
internal ProjectXmlChangedEventArgs(ProjectRootElement projectXml, string unformattedReason, string formattingParameter)
{
ErrorUtilities.VerifyThrowArgumentNull(projectXml, "projectXml");
this.ProjectXml = projectXml;
_unformattedReason = unformattedReason;
_formattingParameter = formattingParameter;
}
示例10: AddItems
private static void AddItems(ProjectRootElement elem, string groupName, params string[] items)
{
var group = elem.AddItemGroup();
foreach (var item in items)
{
group.AddItem(groupName, item);
}
}
示例11: Project
public Project (ProjectRootElement xml, IDictionary<string, string> globalProperties,
string toolsVersion, ProjectCollection projectCollection,
ProjectLoadSettings loadSettings)
{
ProjectCollection = projectCollection;
Xml = xml;
GlobalProperties = globalProperties;
ToolsVersion = toolsVersion;
}
示例12: LoadProjectInstance
internal static ProjectInstance LoadProjectInstance(MSBuild.Evaluation.ProjectCollection projectCollection, ProjectRootElement rootElement, IDictionary<string, string> globalProps)
{
lock (SolutionProjectCollectionLock) {
string toolsVersion = rootElement.ToolsVersion;
if (string.IsNullOrEmpty(toolsVersion))
toolsVersion = projectCollection.DefaultToolsVersion;
return new ProjectInstance(rootElement, globalProps, toolsVersion, projectCollection);
}
}
示例13: UpgradeProject
protected override void UpgradeProject(ref ProjectRootElement projectXml, ref ProjectRootElement userProjectXml, Action<__VSUL_ERRORLEVEL, string> log) {
var envVarsProp = projectXml.Properties.FirstOrDefault(p => p.Name == NodejsConstants.EnvironmentVariables);
if (envVarsProp != null) {
var globals = projectXml.PropertyGroups.FirstOrDefault() ?? projectXml.AddPropertyGroup();
AddOrSetProperty(globals, NodejsConstants.Environment, envVarsProp.Value.Replace(";", "\r\n"));
envVarsProp.Parent.RemoveChild(envVarsProp);
log(__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, SR.GetString(SR.UpgradedEnvironmentVariables));
}
}
示例14: ProjectUsingTaskParameterElement
internal ProjectUsingTaskParameterElement (string name, string output, string required,
string parameterType, ProjectRootElement containingProject)
{
Name = name;
Output = output;
Required = required;
ParameterType = parameterType;
ContainingProject = containingProject;
}
示例15: ResolvedImport
/// <summary>
/// Initializes a new instance of the <see cref="ResolvedImport"/> struct.
/// </summary>
internal ResolvedImport(Project project, ProjectImportElement importingElement, ProjectRootElement importedProject)
{
ErrorUtilities.VerifyThrowInternalNull(importingElement, "parent");
ErrorUtilities.VerifyThrowInternalNull(importedProject, "child");
_importingElement = importingElement;
_importedProject = importedProject;
_isImported = !ReferenceEquals(project.Xml, importingElement.ContainingProject);
}