【发布时间】:2013-12-18 10:22:27
【问题描述】:
我正在关注这个博客:http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx
它在这个问题中作为答案链接:Web.Config transforms outside of Microsoft MSBuild?
每个步骤都按描述进行,但我想从 powershell 脚本调用转换。
我想在 powershell msbuild trans.proj /t:Demo 中执行此命令
我发现一些论坛说我应该使用invoke-expression
当我尝试时,我得到了这个错误
Powershell:
Invoke-Expression $msbuild transformCommand.proj /t:Demo
结果
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>
我的问题是: 这可能吗?这怎么可能?
编辑:
$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
这实际上做了我需要的一切..
如果有更“独立”或更好的方法可以做到这一点,请发布。
【问题讨论】: