如何在多个项目中应用程序集文件版本号? [英] How to apply an assembly file version number over multiple projects ?

查看:75
本文介绍了如何在多个项目中应用程序集文件版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:在多个项目中应用程序集文件版本号。



例如,我有10个项目。每个项目都有Property => AssemblyInfo.cs文件。那里你将有如下所示的AssemblyFileVersion标签。



[assembly:AssemblyFileVersion(1.0.0.0)]



我正在使用AssemblyInfo.tt文件,我希望通过该文件应用Fileversion编号。因此,我从AssemblyInfo.cs文件中删除了Fileversion并创建了一个AssemblyInfo.tt文件,其中我提到了Fileversion并将其添加为链接。是的,它应用于项目,我可以在该项目中看到更新的文件版本。



现在因为我有10个项目,每个项目我需要做同样的上述操作,以便它将应用我通过.tt文件提供的实际文件版本。



这个过程很乏味,我在解决方案中有100多个项目我需要为每个应用一个自定义文件版本。



目标是我第一次将.tt文件添加到所有100个项目中,这将是

位于中心位置[项目的上/父文件夹]以后如果我用新的构建和修订号更改.tt文件,它应该自动应用于所有项目。



作为参考,您可以查看以下链接:

http://stackoverflow.com/questions/826777/how-to-have-an-auto-incrementing-version -number-visual-studio



http://vagif.bloggingabout.net/2010/04/24/using-t4-templates-to-man age-assembly-version-information /





https://msdn.microsoft.com/en-us/library/dd820620.aspx [ ^ ]



了解情况,如果您需要任何额外的信息请告诉我,但不要分享一些无关的例子。



提前致谢!!

Target: Apply an assembly file version number over multiple projects.

For example, I have 10 projects. Each project has Property=> AssemblyInfo.cs file. There you will have AssemblyFileVersion tag as well like below.

[assembly: AssemblyFileVersion("1.0.0.0")]

I am using AssemblyInfo.tt file through which I want to apply Fileversion number. Hence I removed Fileversion from AssemblyInfo.cs file and created a AssemblyInfo.tt file where I mentioned the Fileversion and added it as a link. Yes it is applied to the project and I can see the updated file version in that project.

Now as I have 10 projects, for each project I need to do the same above operation so that it will apply the actual file version which I gave through .tt file.

This process is tedious where I have more than 100 projects in solution and I need to apply a customized file version for each.

The target is for first time I will add .tt file into all 100 projects which will be
in a central position[Upper/parent folder of the projects] and later if I change the .tt file with a new build and revision number it should automatically apply over all projects.

For reference you can look into the below links:
http://stackoverflow.com/questions/826777/how-to-have-an-auto-incrementing-version-number-visual-studio

http://vagif.bloggingabout.net/2010/04/24/using-t4-templates-to-manage-assembly-version-information/


https://msdn.microsoft.com/en-us/library/dd820620.aspx[^]

Understand the situation, If you need any additional information please let me know but don't share some link which are just meaningless examples.

Thanks in advance!!

推荐答案

请参阅我对该问题的评论。这是一个有效的问题。



没有预定义的方法来控制所有项目中的版本同步,但你想要的是一个非常合理的功能你可能想发展自己。我使用了至少两种略有不同的方法。



首先,您可以编写一个小文本实用程序来扫描项目文件(通过名为Properties / AssemblyInfo的文件来限制这种属性的使用是合理的)更改这些文件中的版本。



另一种方法是在特殊的MSBuild 任务中执行相同操作,这可能是另一个项目你的解决方案根据MSBuild标准执行此操作时,可以在一个或多个项目中使用此任务。它可以是专门用于在构建时修改所有其他项目的版本信息的任务的项目。例如,它可以从项目的 Property 值中读取版本,或者从某些文本文件中用作源文件,查找要修改的所有文件并对其进行修改。或者,此类任务可以包含在执行其他操作的项目中,并且可以始终(修改版本时)或仅为此目的添加一个特殊的目标来完成版本修改。这种方法需要更多时间,但它可以简化您的开发版本。您将需要学习自定义MSBuild使用和相关概念。请参阅:

https://msdn.microsoft.com/en-us /library/ms171466.aspx [ ^ ],

https://msdn.microsoft.com/en -us / library / ms171458.aspx [ ^ ],

https://msdn.microsoft.com /en-us/library/dd637714.aspx [ ^ ],

https://msdn.microsoft .com / zh-CN / library / dd393574.aspx [ ^ ]。



-SA
Please see my comment to the question. This is a valid question.

There is no a predefined way of control the version in all project in sync, but what you want would be a very reasonable feature you may want to develop yourself. I used at least two slightly different approaches.

First, you can write a small text utility scanning the project file (it would be reasonable to limit such attribute use by the files named "Properties/AssemblyInfo") and changing the version in these files.

Another approach is to do the same in a special MSBuild Task, which can be yet another project in your solution. When you do it according to the MSBuild standard, you can use this task in one or more of your projects. It can be a project devoted specially for the task of modifying version information of all other projects when it is build. For example, it can read version from a project's Property value, or from some text file uses as a source file, finds all files to be modifies and modifies them. Alternatively, such task can be included in a project doing something else, and the version modification can be done either always (when version is modified), or only for one special Target added for this purpose. This approach will need more time, but it could streamline your development versioning. You will need to learn custom MSBuild use and related concepts. Please see:
https://msdn.microsoft.com/en-us/library/ms171466.aspx[^],
https://msdn.microsoft.com/en-us/library/ms171458.aspx[^],
https://msdn.microsoft.com/en-us/library/dd637714.aspx[^],
https://msdn.microsoft.com/en-us/library/dd393574.aspx[^].

—SA


当我想这样做时,我通常在解决方案文件夹中创建一个GlobalAssemblyInfo.cs文件,我在其中设置AssemblyVersion和/或AssemblyFileVersion属性。



然后,对于每个项目,我将此文件添加为现有文件,并选择链接它而不是复制它。



然后,我确保为每个项目中的每个AssemblyInfo.cs文件删除在GlobalAssemblyInfo.cs文件中设置的属性。



我希望我足够清楚。如果您需要更多解释,请告诉我。
When I want to do that, I usually create a GlobalAssemblyInfo.cs file in a solution folder, in which I set the AssemblyVersion and/or AssemblyFileVersion attribute(s).

Then, for each project, I add this file as an already existing file, with the option of linking it instead of copying it.

Then, I make sure that, for each AssemblyInfo.cs file in each project, I delete the attributes that are set in the GlobalAssemblyInfo.cs file.

I hope I was clear enough. Please let me know if you need some more explanations.


这篇关于如何在多个项目中应用程序集文件版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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