我使用的是安装项目发布我的项目。 我希望每个项目的版本是一样的安装版本。
我想改变在Visual Studio和建设,工程项目的全部版本从这个属性更新后,我的设置版本属性,这可能吗?
我使用的是安装项目发布我的项目。 我希望每个项目的版本是一样的安装版本。
我想改变在Visual Studio和建设,工程项目的全部版本从这个属性更新后,我的设置版本属性,这可能吗?
项目大会和文件版本号:(未安装的版本,我按编辑你的问题)
答1:
如果你想设置你需要一个脚本/ EXE,它被通过构建触发做大会和文件版本号的安装项目版本号。
本文就如何更新程序集版本号自动显示一半的解决方案......
从研究我做到了不可能使用SetupVersion在PreBuildEvent。 没有为它$ SetupVersion命令: http://msdn.microsoft.com/en-us/library/42x5kfw4(v=vs.80).aspx
不必更改PreBuildEvent每个构建如图此评论使用的代码项目的文章中-set:
命令是不理想的。
我们需要的解决方案是一个PreBuildEvent调用AssemblyInfoUtil.exe并使其读取来自vdproj项目文件“的ProductVersion”。 然后更新程序集的版本号(一个或多个)。
我已经修改了代码的文章向您展示如何读取来自Setup.vdproj的产品版本,这是它如何从一个PreBuildEvent被称为:
AssemblyInfoUtil.exe -setup:"C:\Program Files\MyProject1\Setup1\Setup1.vdproj" -ass:"C:\Program Files\MyProject1\AssemblyInfo.cs"
这是修改后的代码:
using System;
using System.IO;
using System.Text;
namespace AssemblyInfoUtil
{
class AssemblyInfoUtil
{
private static int incParamNum = 0;
private static string fileName = "";
private static string setupfileName = "";
private static string versionStr = null;
private static bool isVB = false;
[STAThread]
static void Main(string[] args)
{
for (int i = 0; i < args.Length; i++) {
if (args[i].StartsWith("-setup:")) {
string s = args[i].Substring("-setup:".Length);
setupfileName = int.Parse(s);
}
else if (args[i].StartsWith("-ass:")) {
fileName = args[i].Substring("-ass:".Length);
}
}
//Jeremy Thompson showing how to detect "ProductVersion" = "8:1.0.0" in vdproj
string setupproj = System.IO.File.ReadAllText(setupfileName);
int startPosOfProductVersion = setupproj.IndexOf("\"ProductVersion\" = \"") +20;
int endPosOfProductVersion = setupproj.IndexOf(Environment.NewLine, startPosOfProductVersion) - startPosOfProductVersion;
string versionStr = setupproj.Substring(startPosOfProductVersion, endPosOfProductVersion);
versionStr = versionStr.Replace("\"", string.Empty).Replace("8:",string.Empty);
if (Path.GetExtension(fileName).ToLower() == ".vb")
isVB = true;
if (fileName == "") {
System.Console.WriteLine("Usage: AssemblyInfoUtil
<path to :Setup.vdproj file> and <path to AssemblyInfo.cs or AssemblyInfo.vb file> [options]");
System.Console.WriteLine("Options: ");
System.Console.WriteLine(" -setup:Setup.vdproj file path");
System.Console.WriteLine(" -ass:Assembly file path");
return;
}
if (!File.Exists(fileName)) {
System.Console.WriteLine
("Error: Can not find file \"" + fileName + "\"");
return;
}
System.Console.Write("Processing \"" + fileName + "\"...");
StreamReader reader = new StreamReader(fileName);
StreamWriter writer = new StreamWriter(fileName + ".out");
String line;
while ((line = reader.ReadLine()) != null) {
line = ProcessLine(line);
writer.WriteLine(line);
}
reader.Close();
writer.Close();
File.Delete(fileName);
File.Move(fileName + ".out", fileName);
System.Console.WriteLine("Done!");
}
private static string ProcessLine(string line) {
if (isVB) {
line = ProcessLinePart(line, "<Assembly: AssemblyVersion(\"");
line = ProcessLinePart(line, "<Assembly: AssemblyFileVersion(\"");
}
else {
line = ProcessLinePart(line, "[assembly: AssemblyVersion(\"");
line = ProcessLinePart(line, "[assembly: AssemblyFileVersion(\"");
}
return line;
}
private static string ProcessLinePart(string line, string part) {
int spos = line.IndexOf(part);
if (spos >= 0) {
spos += part.Length;
int epos = line.IndexOf('"', spos);
string oldVersion = line.Substring(spos, epos - spos);
string newVersion = "";
bool performChange = false;
if (incParamNum > 0) {
string[] nums = oldVersion.Split('.');
if (nums.Length >= incParamNum && nums[incParamNum - 1] != "*") {
Int64 val = Int64.Parse(nums[incParamNum - 1]);
val++;
nums[incParamNum - 1] = val.ToString();
newVersion = nums[0];
for (int i = 1; i < nums.Length; i++) {
newVersion += "." + nums[i];
}
performChange = true;
}
}
else if (versionStr != null) {
newVersion = versionStr;
performChange = true;
}
if (performChange) {
StringBuilder str = new StringBuilder(line);
str.Remove(spos, epos - spos);
str.Insert(spos, newVersion);
line = str.ToString();
}
}
return line;
}
}
}
答2:
要我想一个更好的办法的办法是使用一个共享程序集信息类,而不是单个的AssemblyInfo类文件。
为了实现这一点,创建解决方案文件夹名为SharedAssemblyInfo.cs一个文件,然后在每个项目中添加一个链接到SharedAssemblyInfo.cs。 您还可以将链接SharedAssemblyInfo.cs到Properties文件夹,以便它位于并排侧与特定解决方案中的每个项目,如下图所示的AssemblyInfo.cs。
下面是一个示例SharedAssemblyInfo.cs文件:
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyCompany("Saint Bart Technologies")]
[assembly: AssemblyProduct("Demo")]
[assembly: AssemblyCopyright("Copyright ? Saint Bart 2013")]
[assembly: AssemblyTrademark("")]
// Make it easy to distinguish Debug and Release (i.e. Retail) builds;
// for example, through the file properties window.
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Flavor=Debug")] // a.k.a. "Comments"
#else
[assembly: AssemblyConfiguration("Retail")]
[assembly: AssemblyDescription("Flavor=Retail")] // a.k.a. "Comments"
#endif
[assembly: CLSCompliant(true)]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// Note that the assembly version does not get incremented for every build
// to avoid problems with assembly binding (or requiring a policy or
// <bindingRedirect> in the config file).
//
// The AssemblyFileVersionAttribute is incremented with every build in order
// to distinguish one build from another. AssemblyFileVersion is specified
// in AssemblyVersionInfo.cs so that it can be easily incremented by the
// automated build process.
[assembly: AssemblyVersion("1.0.0.0")]
// By default, the "Product version" shown in the file properties window is
// the same as the value specified for AssemblyFileVersionAttribute.
// Set AssemblyInformationalVersionAttribute to be the same as
// AssemblyVersionAttribute so that the "Product version" in the file
// properties window matches the version displayed in the GAC shell extension.
[assembly: AssemblyInformationalVersion("1.0.0.0")] // a.k.a. "Product version"
下面是一个示例AssemblyInfo.cs文件:
// Note: Shared assembly information is specified in SharedAssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WindowsFormsApplication2")]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ffded14d-6c95-440b-a45d-e1f502476539")]
所以每次你想改变所有项目大会信息,你可以做它在一个地方。 我假设你想设置的MSI安装程序版本一样大会的版本号,一个手动工序。
答3:
考虑切换到使用的MSBuild它拥有所有这些类型的好处,但我不知道,如果你有时间去把它捡起来,现在。
答4:
使用的AssemblyInfo.cs内的下列星号语法组件可以自动增加它的版本号:
[assembly: AssemblyVersion("1.0.0.*")]
这是一个很好的方法,因为跟踪版本号的关键是能够识别不同的版本。 具有预构建变化的内部版本号为失败尚未发生构建这一目的。
答5:
其他CodeProject上回答这里假设你想更新ProductVersion, ProductCode, PackageCode
在安装MSI项目文件。 我没有理解你的问题这种方式,并根据这个线索有问题: 预生成事件来改变设置项目的ProductVersion不会生效,直到生成后
答6(新):
有几个TFS构建插件设置“大会信息”: https://marketplace.visualstudio.com/items?itemName=bleddynrichards.Assembly-Info-Task https://marketplace.visualstudio.com/items?itemName=bool .update具组件信息 https://marketplace.visualstudio.com/items?itemName=ggarbuglia.setassemblyversion-task
我不知道这是否完美地解决您的问题,但你可以实现与所有configmanagment信息像一个普通类:
public class VersionInfo{
public const string cProductVersion = "1.0.0"
//other version info
}
后,您可以更新与新课程的所有的AssemblyInfo.cs:
[assembly: AssemblyVersion(VersionInfo.cProductVersion)]
我希望这有帮助。