gpt4 book ai didi

msbuild - 从 powershell 执行 msbuild 任务

转载 作者:行者123 更新时间:2023-12-04 17:35:35 25 4
gpt4 key购买 nike

我正在关注这个博客:http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx

它在这个问题中作为答案链接:Web.Config transforms outside of Microsoft MSBuild?

每一步都按描述进行,但我想从 powershell 脚本调用转换。
我想在 powershell 中执行此命令 msbuild trans.proj /t:Demo我发现一些论坛说我应该使用 invoke-expression
当我尝试时出现此错误

电源 shell :

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。

转换命令.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

这实际上做了我需要的一切..

如果有更“独立”或更好的方法来做到这一点,请发布它。

最佳答案

确保在调用 Invoke-Expression $msbuild 之前定义 PowerShell 变量 $msbuild

$msbuild = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"

关于msbuild - 从 powershell 执行 msbuild 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20655456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com