MSBuild:从命令行指定目标 [英] MSBuild: Specifying a target from the command line

查看:95
本文介绍了MSBuild:从命令行指定目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MSBuild任务,可以在解决方案文件中构建特定项目.看起来像这样:

I have an MSBuild task to build a specific project in a solution file. It looks something like this:

<Target Name="Baz">
  <MSBuild Projects="Foo.sln" Targets="bar:$(BuildCmd)" />
</Target>

在命令行中,我可以将BuildCmd设置为RebuildClean,并且可以按预期工作:

From the command line, I can set my BuildCmd to either Rebuild or Clean and it works as expected:

msbuild/target:Baz/property:BuildCmd =重建MyMsbuildFile.xml msbuild/target:Baz/property:BuildCmd =清理MyMsbuildFile.xml

msbuild /target:Baz /property:BuildCmd=Rebuild MyMsbuildFile.xml msbuild /target:Baz /property:BuildCmd=Clean MyMsbuildFile.xml

但是我要用什么词来设置BuildCmd以便进行构建?我已经尝试过BuildCompile并将其保留为空白或未定义,但是我总是收到错误消息.

But what word do I use to set BuildCmd to in order to just build? I've tried Build and Compile and just leaving it blank or undefined, but I always get an error.

msbuild/target:Baz/property:BuildCmd = Build MyMsbuildFile.xml Foo.sln:错误MSB4057:项目中不存在目标"bar:Build".

msbuild /target:Baz /property:BuildCmd=Build MyMsbuildFile.xml Foo.sln : error MSB4057: The target "bar:Build" does not exist in the project.

msbuild/target:Baz/property:BuildCmd =编译MyMsbuildFile.xml Foo.sln:错误MSB4057:项目中不存在目标"bar:Compile".

msbuild /target:Baz /property:BuildCmd=Compile MyMsbuildFile.xml Foo.sln : error MSB4057: The target "bar:Compile" does not exist in the project.

msbuild/target:Baz MyMsbuildFile.xml Foo.sln:错误MSB4057:项目中不存在目标栏:".

msbuild /target:Baz MyMsbuildFile.xml Foo.sln : error MSB4057: The target "bar:" does not exist in the project.

推荐答案

我了解到您想使用特定命令来构建目标:Build,Clean等.

I understood that you want to build a target with a specific command: Build, Clean, etc.

这就是我要做的.

创建一个属性以接收您的构建命令,如果未指定则默认为Build

Create a property to receive your build command, when not specified defaults to Build

<PropertyGroup>
  <BuildCmd Condition=" '$(BuildCmd)' == ''">Build</BuildCmd>
</PropertyGroup>

之后,创建将使用参数中的指定目标启动MSBuild的目标:

After, create the target that will start MSBuild with the specified target in the parameter:

<Target Name="Stackoverflow">
  <MsBuild Projects="Foo.sln" Targets="$(BuildCmd)" />
</Target>

然后使用目标和BuildCmd参数调用您的MSBuild文件,如下所示:

Then call your MSBuild file with the target and BuildCmd parameter like so:

msbuild msbuild.xml /t:Stackoverflow /p:BuildCmd=Clean

只需确保目标存在于解决方案或项目文件中即可.

Just make sure the target exists in the solution or project file.

这篇关于MSBuild:从命令行指定目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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