MSBuild建立后 [英] MSBuild Post-Build

查看:133
本文介绍了MSBuild建立后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了构建后的步骤,我已经拥有一个MSBuild脚本,它可以完成我需要做的所有事情(请参阅我之前问过的一个问题: MSBuild条件执行程序?)。

I've got an MSBuild script that is just about doing everything that I need it to do apart from my post-build step (see a previous question that I asked: MSBuild conditional Exec?).

我要执行的操作是构建许多csproj文件并如果且仅当项目已构建时,可以选择执行构建后步骤。我不想一直执行我的构建后步骤,否则将不必要地修改最终输出中的时间戳(这会毫无原因地使构建过程非常耗时)。

What I'm looking to do is build many csproj files and optionally perform post-build steps if and only if the project was built. I don't want to perform my post-build step all the time or else the timestamp on my final output will be modified unnecessarily (and it makes the build process very time consuming for no reason).

在我的MSBuild脚本中,我的每个csproj文件都具有以下内容:

In my MSBuild script I've got something like the following for each of my csproj files:

<Target Name="ProjectName">
   <MSBuild Projects="PathToProject" Properties="Configuration=$(buildtype)" />
</Target>

编辑:
我认为我真正想做的是检测何时为每个项目运行CoreCompile任务。如果有某种条件可以检查这种情况?

I think what I really want to do is detect when the CoreCompile task runs for each project. If there were some way to check for this in a condition?

有什么想法吗?

我是新手到MSBuild,所以也许我走的路完全错了!

I'm new to MSBuild so maybe I'm on completely the wrong track!

谢谢,
艾伦

推荐答案

在为该问题寻找了一个简单的解决方案之后,我没有找到一个解决方案,最终提出了自己的解决方案,但可能不是最佳解决方案。但是,我想与遇到相同问题的其他任何人共享它,以便您至少可以有一个可行的解决方案,并希望为您省去很多麻烦。

After much searching for a simple solution to this problem I didn't find one and ended up coming up with a solution of my own that works but may not be the best solution. However, I wanted to share it with anyone else that is having the same problem so that you can at least have a working solution and hopefully saving you a lot of head banging.

总而言之,我想做的是在构建项目后运行命令行工具,但前提是要更新程序集(即更改时间戳)。我不想将其放入每个项目的后构建部分,因为我只希望后构建在我们的构建服务器(而不是开发机器)上进行。

To recap, what I wanted to do was run a command line tool after my project was built but only if the assembly was updated (i.e. the timestamp changed). I didn't want to put this into the post-build section of every project because I only wanted the post-build to happen on our build server (not development machines).

我在主.proj文件中找不到任何从外部进行此操作的方法,并且最终更改了每个.csproj文件的post-build部分。但是,我给它加上了if条件,例如:

I didn't find any way of doing this externally in my main .proj file and did end up altering the post-build section of each .csproj file. However, I prefixed it with an if condition something like this:

if '$(ExecuteCommand)' == 'true' command.exe

这意味着该命令永远不会在开发计算机上执行,而是在我调用构建时从我的.proj文件中,我可以将该标志设置为true:

This means that the command will never be executed on the development machine but when I invoke the build from my .proj file I can set that flag to true like this:

<!-- Define common properties -->
<PropertyGroup>
    <ExecuteCommand>true</ExecuteCommand>
</PropertyGroup>

<Target Name="YourTarget">
    <!-- Build project -->
    <MSBuild Projects="Path to project" Properties="ExecuteCommand=$(ExecuteCommand)" />
</Target>

正如我所说,我认为这不是最优雅的解决方案,但它肯定会起作用并且会暂时对我来说足够了。但是,我仍然想听听实现此目标的正确方法是什么,以便我可以改进自己的脚本。

As I said, I don't think it is the most graceful solution but it certainly works and will be sufficient for me for the time being. However, I'd still be interested to hear what the proper way of achieving this is so that I can improve my script.

谢谢,
Alan

Thanks, Alan

这篇关于MSBuild建立后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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