从Powershell执行msbuild任务 [英] Executing msbuild task from powershell

查看:534
本文介绍了从Powershell执行msbuild任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

它在此问题中的链接为答案: Microsoft外部的Web.Config转换MSBuild?

it's linked in this question as answer: Web.Config transforms outside of Microsoft MSBuild?

每个步骤均按所述方式工作,但我想从Powershell脚本调用转换. 我想在Powershell msbuild trans.proj /t:Demo中执行此命令 我发现一些论坛上说我应该使用invoke-expression

Every step works as described but I want to call the transformation from a powershell script. I want to do this command in powershell msbuild trans.proj /t:Demo I found some forums saying that I should use invoke-expression

尝试时出现此错误

Powershell:

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.

Small note: this is my first time using powershell.

TransformCommand.proj

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>

我的问题是: 这可能吗?怎么可能呢?

My questions are: Is this possible? And how is it possible?

$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 

这实际上可以满足我的所有需求.

This actually does everything I need..

如果仍然有更多方法可以做到这种独立"或更好的方法,请发布.

Still if there are ways to do this more "indepent" or better ways, please post it.

推荐答案

在调用Invoke-Expression $ msbuild

Make sure you define the PowerShell variable $msbuild as below before calling Invoke-Expression $msbuild

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

这篇关于从Powershell执行msbuild任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆