我正在关注这个博客:http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx
它在这个问题中作为答案链接:Web.Config 在 Microsoft MSBuild 之外进行转换? https://stackoverflow.com/questions/8989737/web-config-transforms-outside-of-microsoft-msbuild
每个步骤都按描述进行,但我想从 powershell 脚本调用转换。
我想在 powershell 中执行此命令msbuild trans.proj /t:Demo
我发现一些论坛说我应该使用invoke-expression
当我尝试时出现此错误
电源外壳:
Invoke-Expression $msbuild transformCommand.proj /t:Demo
Result
Invoke-Expression : Cannot bind argument to parameter 'Command' because it is null.
At D:/Somewhere
+ Invoke-Expression <<<< $msbuild transformCommand.proj /t:Demo
+ CategoryInfo : InvalidData: (:) [Invoke-Expression], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.InvokeExpre
ssionCommand
我也尝试过:
Invoke-Expression msbuild transformCommand.proj /t:Demo
有结果
D:\Somewhere
Invoke-Expression : A positional parameter cannot be found that accepts argument 'transformCommand.proj'.
At D:\Redgate\Communited.Timeblockr.Api\PreDeploy1.ps1:14 char:18
+ Invoke-Expression <<<< msbuild transformCommand.proj /t:Demo
+ CategoryInfo : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand
小提示:这是我第一次使用 powershell。
TransformCommand.proj
<Project ToolsVersion="4.0" DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
<Target Name="Demo">
<TransformXml Source="Web.Test.config"
Transform="transform.xml"
Destination="Web.acceptatie.config"/>
</Target>
</Project>
我的问题是:
这可能吗?这怎么可能呢?
Edit:
$a = "Path\transformCommand.proj /t:Demo"
#Invoke-Expression $msbuild $a
Start-Process -FilePath "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" -ArgumentList $a | Write-Host
这实际上满足了我需要的一切..
不过,如果有方法可以更“独立”或更好地做到这一点,请发布。