2017-07-10 20 views
2

我有一個批處理文件,我試圖用Cake(C#Make)進行復制。它使用一些屬性打電話給MSBuild。這是批次中的一行;蛋糕MSBuild設置屬性

"%MSBuildPath%msbuild.exe" ..\public\projectToBeBuilt.sln /t:Rebuild /p:Configuration=RELEASE;platform=%platform% /maxcpucount:%cpucount% /v:%verboselevel% 

這些是我需要設置的屬性。我認爲它是這樣的;

MSBuild(@"..\public\projectToBeBuilt.sln", s=> s.SetConfiguration("Release") 
    .UseToolVersion(MSBuildToolVersion.Default) 
    .WithProperty("Verbosity", Verbosity) 
    .WithProperty("MaxCpuCount", cpuCount) 
    .WithProperty("Platform", "x64") 
    .WithProperty("OutDir", buildDir)); 

我在做這項工作時遇到了麻煩。我認爲這可能與我指定CPU數量有關。我也無法找到任何方法將其設置爲重建,批處理的方式。

回答

7

你得到了什麼樣的錯誤?

要重建就像你在你的批處理例子中,你將使用WithTarget這樣

.WithTarget("Rebuild") 

關於CPU數目我沒有問題,如果我這樣設置

.SetMaxCpuCount(System.Environment.ProcessorCount) 

設置平臺設定的目標做會看起來像這樣

.SetPlatformTarget(PlatformTarget.x64) 

設置詳細程度爲

.SetVerbosity(Verbosity) 

所以,一個完整的命令可能看起來像

MSBuild(solution, settings => 
    settings.SetConfiguration("Release") 
     .UseToolVersion(MSBuildToolVersion.Default) 
     .WithTarget("Rebuild") 
     .SetMaxCpuCount(cpuCount) 
     .SetPlatformTarget(PlatformTarget.x64) 
     .SetVerbosity(Verbosity) 
     .WithProperty("OutDir", buildDir) 
     ); 

爲的MSBuild設置流暢API方法都記錄here

+0

謝謝!這看起來像我正在尋找的。我無法在任何地方找到.WithTarget()方法的示例。我的解決方法是創建一個MSBuild任務依賴的「乾淨」任務。這清除了bin文件夾,強制新建立。我想這將有相同的結果。我弄清楚使用.SetMaxCpuCount(0)將使用可用的最大處理器數量。再次感謝您的幫助! – MtnBuckNasty

+0

SetMaxCpuCount爲0將導致使用代理程序中可用的CPU數量。 – Miguel