首页 > 解决方案 > How do I get just the Major part of version inside AfterBuild target

问题描述

How do I get just the Major part of the version in AfterBuild target? I thought I could access the property like shown below, but it just echoes the statement rather than show version.

  <Target Name="AfterBuild">
    <GetAssemblyIdentity
        AssemblyFiles="$(MyAssemblies)">
      <Output
          TaskParameter="Assemblies"
          ItemName="MyAssemblyIdentities"/>
    </GetAssemblyIdentity>

    <Message Text="Files: %(MyAssemblyIdentities.Version.Major)"/>
  </Target>

Here is the working code in Program.cs

 var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
 Console.WriteLine(String.Format("My Application Version {0}", version.Major));

标签: c#msbuild

解决方案


推荐阅读