public IEnumerable <ITaskItem> GetAssemblyReferences(Microsoft.Build.Construction.ProjectRootElement projectRootElement) { ConsoleLogger logger = new ConsoleLogger(LoggerVerbosity.Normal); BuildManager manager = BuildManager.DefaultBuildManager; ProjectInstance projectInstance = new ProjectInstance(projectRootElement); var result = manager.Build( new BuildParameters() { DetailedSummary = true, Loggers = new List <ILogger>() { logger } }, new BuildRequestData(projectInstance, new string[] { "ResolveProjectReferences", "ResolveAssemblyReferences" })); var projectReferences = GetAssemblyReferencesList(result, "ResolveProjectReferences"); var assemblyReferences = GetAssemblyReferencesList(result, "ResolveAssemblyReferences"); var results = projectReferences.Union(assemblyReferences); return(results); }
static MsBuild.Construction.ProjectPropertyElement CreateProperty(MsBuild.Construction.ProjectRootElement project, string name, string value, string condition = null) { var propertyElement = project.CreatePropertyElement(name); propertyElement.Value = value; propertyElement.Condition = condition; return(propertyElement); }
public override async Task <string> OnGetEvaluatedPropertyValueAsync( string evaluatedPropertyValue, IProjectProperties defaultProperties) { using (ProjectLockReleaser access = await _projectLockService.ReadLockAsync()) { Microsoft.Build.Construction.ProjectRootElement projectXml = await access.GetProjectXmlAsync(_unconfiguredProject.FullPath); return(await _helper.GetPropertyAsync(projectXml, defaultProperties)); } }
public override async Task <string> OnSetPropertyValueAsync( string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string> dimensionalConditions = null) { using (ProjectWriteLockReleaser access = await _projectLockService.WriteLockAsync()) { Microsoft.Build.Construction.ProjectRootElement projectXml = await access.GetProjectXmlAsync(_unconfiguredProject.FullPath); await _helper.SetPropertyAsync(unevaluatedPropertyValue, defaultProperties, projectXml); } return(null); }
public Project LoadProject(string path) { using FileStream stream = new(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.Asynchronous); using StreamReader readStream = new(stream); using var xmlReader = XmlReader.Create(readStream, s_xmlReaderSettings); var xml = ProjectRootElement.Create(xmlReader); xml.FullPath = path; return(new(xml)); }
protected Microsoft.Build.Construction.ProjectRootElement GetProjectContent() { if (_projectContent == null) _projectContent = Microsoft.Build.Construction.ProjectRootElement.Open(this.FullName); return _projectContent; }
public void Load(string path_project) { //BuildResult result = null; using (ProjectCollection collection = new ProjectCollection()) { /* * result = BuildManager.DefaultBuildManager.Build( * new BuildParameters(pc) { Loggers = new[] { new ConsoleLogger() } }, * // Change this path to your .sln file instead of the .csproj. * // (It won't work with the .csproj.) * new BuildRequestData(@"c:\projects\Sample.sln", * // Change the parameters as you need them, * // e.g. if you want to just Build the Debug (not Rebuild the Release). * new Dictionary<string, string> * { * { "Configuration", "Release" }, * { "Platform", "Any CPU" } * }, null, new[] { "Rebuild" }, null)); * * if (result.OverallResult == BuildResultCode.Failure) * { * } */ /* * collection. * Microsoft.Build.Evaluation.Project proj = collection.LoadProject(path_project); // <-- exception * * proj.Build("Build"); */ collection.DefaultToolsVersion = "15.0"; Microsoft.Build.Evaluation.Project p = null; Microsoft.Build.Construction.ProjectRootElement pre = null; pre = Microsoft.Build.Construction.ProjectRootElement.Open(path_project); //p = collection.LoadProject //( // path_project, // new Dictionary<string, string>(), // "15.0", // new ProjectCollection() //); p = new Microsoft.Build.Evaluation.Project(pre); //( // path_project, // new Dictionary<string, string>(), // "15.0", // new ProjectCollection() //); p.ProjectCollection.RegisterLogger(new ConsoleLogger()); p.ProjectCollection.SetGlobalProperty("EnableNuGetPackageRestore", "true"); p.Build(); if (!p.Build()) { Console.ReadLine(); } //MsBuildProject return; } }