的MSBuild用于更新集信息文件

的MSBuild用于更新集信息文件

本文介绍了的MSBuild用于更新集信息文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个批处理文件来自动执行一系列任务。其中一项任务是更新DLL的版本在我的解决方案,通过编辑在我的解决方案的各个项目的AssemblyInfo.cs文件;然后最后调用msbuild.exe来编译解决方案。

I am writing a batch file to automate a series of tasks. One of these tasks is to update the version of the dlls in my solution, by editing the assemblyinfo.cs file in the various projects in my solution; and then finally calling msbuild.exe to compile the solution.

在这方面,是不是可以编写一个命令行脚本来更新我的.NET解决方案的各种AssemblyInfo.cs中的文件。我想preFER来从命令行调用的MSBuild本身,而不是创建另一个的MSBuild脚本文件。

In this regard, is it possible to write a command line script to update the various assemblyinfo.cs files in my .net solution. I would prefer to call msbuild from the commandline itself and not create another msbuild scripted file.

如何使用MSBuild的一种实现这一目的?有没有其他办法做到这一点?

How does one do this using MSBuild? Is there any other way to do it?

感谢您的时间...

推荐答案

编辑文件与DOS CMD批处理文件是pretty的毛毛没有其他工具的帮助。您需要使用类似FOR / F命令来逐步通过线,然后再处理每一行。例如寻找那些开头的行:[总成:的AssemblyVersion并用别的东西代替它。

Editing files with dos cmd batch files is pretty hairy without the help of other tools.You would need to use something like the for /f command to step through the lines, and then process each line. For example look for the line that starts: "[assembly: AssemblyVersion"and replace it with something else.

不过,如果你没有太多的在你的AssemblyInfo.cs(记住,你可以,如果你想在AssemblyInfo.cs中拆分为多个CS文件),我建议你从头开始创建该文件与一对夫妇的回应声明

However, if you don't have much in your AssemblyInfo.cs (and remember you can split the AssemblyInfo.cs into multiple cs files if you want) I'd suggest creating the file from scratch with a couple of echo statements.

如果您有可用喜欢sed.exe的编辑可以很容易地完成。其他工具

If you have other tools available like sed.exe the edits can be done easily.

我的preference这几天会去一个微不足道的PowerShell脚本,这可能吃这种早餐,让您访问.NET库,如果你需要它。

My preference these days would be to go for a trivial powershell script, that could eat this for breakfast and gives you access to the .Net libraries if you need it.

下面是它的一个模板形式:

Here's a templating form of it:

(Get-Content AssemblyInfo.template.cs) -replace "{version}","1.2.3.4" > AssemblyInfo.cs

下面是一个使用常规EX pressions更换任何版本号的形式有:

Here's a form that uses regular expressions to replace whatever version number is there:

$x = 'Version("{0}")' -f "1.2.3.4"
$content = Get-Content AssemblyInfo.cs
$content -replace 'Version\(".*"\)',$x > AssemblyInfo.cs

这篇关于的MSBuild用于更新集信息文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 05:19