2013-02-27 4 views
4

MSBUILD API를 사용하여 서비스를 사용하여 솔루션을 구축하고 있습니다.API를 사용할 때 MSBUILD에서 프로젝트 유형 건너 뛰기/제외

예를 들면

내가 할 수 있기를 원하는 것은
var pc = new ProjectCollection(); 
var buildProperties = new Dictionary<string, string> 
{ 
    {"Configuration", "Release"}, 
    {"Platform", "Any CPU"}, 
    {"OutputPath", _outputPath} 
}; 

var buildParameters = new BuildParameters(pc); 

var buildRequest = new BuildRequestData(_buildFile, buildProperties, null, new[] { "Clean", "Rebuild" }, null);    

var buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest); 

제외 프로젝트 유형 또는 확장의 목록을 전달합니다. I로 시작 제외 할 :

  • 데이터베이스는
  • WinRT는
  • 일반 MSBUILD 파일 (NO 프로젝트 형식 GUID를) 프로젝트 프로젝트.

일부 매개 변수를 MSBUILD 관리자에게 전달하여이를 해결할 수있는 방법이 있습니까?

답변

4

이 필요하시면 아주 아니지만, 난 그냥이 코드는 유용 할 수 있습니다 오래된 일 - 작업 중 msbuild를 API를 주위에 일 처리 할 일이,하고 생각 :

var basePath = "path-to-where-source-is"; 
var outputDir = "path-to-output"; 

// Setup some properties that'll apply to all projs 
var pc = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection; 
pc.SetGlobalProperty("Configuration", "Debug"); 
pc.SetGlobalProperty("Platform", "Any CPU"); 
pc.SetGlobalProperty("OutDir", outputDir); 

// Generate the metaproject that represents a given solution file 
var slnProjText = SolutionWrapperProject.Generate(
    Path.Combine(basePath, "NAME-OF-SOLUTION-FILE.sln"), 
    "4.0", 
    null); 

// It's now a nice (well, ugly) XML blob, so read it in 
using(var srdr = new StringReader(slnProjText)) 
using(var xrdr = XmlReader.Create(srdr)) 
{ 
    // Load the meta-project into the project collection   
    var slnProj = pc.LoadProject(xrdr, "4.0"); 

    // Slice and dice the projects in solution with LINQ to 
    // get a nice subset to work with 
    var solutionProjects = 
     from buildLevel in Enumerable.Range(0, 10) 
     let buildLevelType = "BuildLevel" + buildLevel 
     let buildLevelItems = slnProj.GetItems(buildLevelType) 
     from buildLevelItem in buildLevelItems 
     let include = buildLevelItem.EvaluatedInclude 
     where !include.Contains("Some thing I don't want to build") 
     select new 
     { 
      Include=include, 
      Project = pc.LoadProject(Path.Combine(basePath, include)) 
     }; 

    // For each of them, build em! 
    foreach (var projectPair in solutionProjects) 
    { 
     var project = projectPair.Project; 
     var include = projectPair.Include; 
     var outputPath = outputDir; 
     project.SetProperty("OutputPath", outputPath); 
     Console.WriteLine("Building project:" + project.DirectoryPath); 
     var buildOk = project.Build("Build"); 
     if(buildOk) 
     { 
      Console.WriteLine("Project build success!"); 
     } 
     else 
     { 
      throw new Exception("Build failed"); 
     } 
    } 
} 
+0

SolutionWrapperProject는 바보가 될 것 같습니다! – Doug

+1

Yessir - 솔루션 래퍼는 솔루션 구문 (레거시 라덴 혼란)에서 msbuild 프로젝트 구문으로의 변환을 처리합니다.이 구문은 훨씬 좋으며 (적절한 xml) – JerKimball

관련 문제