工作和生成的最简单的嵌入式构建调用输出为:
[void][System.Reflection.Assembly]::Load('Microsoft.Build.Engine, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
$engine = New-Object Microsoft.Build.BuildEngine.Engine
$engine.RegisterLogger((New-Object Microsoft.Build.BuildEngine.ConsoleLogger))
$engine.BuildProjectFile('fullPath\some.proj')
然而,事实证明,直接在PowerShell中(V1)嵌入的MSBuild是有问题的:
'MSBUILD : warning MSB4056: The MSBuild engine must be called on
a single-threaded-apartment. Current threading model is "MTA".
Proceeding, but some tasks may not function correctly.'
为什么啊,为什么我们仍然支付COM税于2009年在托管环境中工作时?
我的结论是,在PowerShell(V1)中嵌入MSBuild不是一个好主意。作为参考,我也包括了基于流程的方法我最后使用:
[void][System.Reflection.Assembly]::Load('Microsoft.Build.Utilities.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
$msbuild = [Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToDotNetFrameworkFile("msbuild.exe", "VersionLatest")
&$msbuild fullPath\some.proj
那么这是我的问题 - 你有任何链接到“关于如何使用它的许多样本”或提供你自己的? – 2009-01-23 14:06:20