1

I am not pretty familiar with msbuild technique. Currently I have a build.proj in my solution to assign a build number to the exe, by using a following param:

      <PropertyGroup Condition=" '$(BUILD_NUMBER)' != '' ">
<!-- Build Server Number -->
<Version>$(BUILD_NUMBER)Version>
<FileVersion>$(BUILD_NUMBER)FileVersion>
<InformationalVersion>$(BUILD_NUMBER)InformationalVersion></PropertyGroup><Target Name="Version">
<Attrib Files="$(MSBuildProjectDirectory)\AssemblyInfo.cs" ReadOnly="False" />
<AssemblyInfo CodeLanguage="CS"
              OutputFile="$(MSBuildProjectDirectory)\GlobalAssemblyInfo.cs"
              GenerateClass="true"
              AssemblyCopyright="Copyright © $(Year). All rights reserved."
              AssemblyConfiguration="$(BuildConfiguration)"
              AssemblyVersion="$(Version)"
              AssemblyFileVersion="$(FileVersion)"
              AssemblyInformationalVersion="$(InformationalVersion)" />  </Target>

Now I can't use build.proj. Is it any alternative way to assign a build number to csproj?

GenZiy
  • 1,427
  • 2
  • 15
  • 20
  • 1
    How do these parameters end-up in your EXE when you use build.proj? A .csproj file is just a build file as well. You can copy over the relevant bits from the build.proj to the .csproj and it should still work. How do you plan to fill the buildnumber property in the .csproj scenario? – rene Oct 27 '17 at 12:52
  • good question, they ended up in AssemblyInfo.cs file which been edited by Build.proj. I am adding that code to the question – GenZiy Oct 27 '17 at 13:01
  • Your .csproj still references that `$(MSBuildProjectDirectory)\GlobalAssemblyInfo.cs`? – rene Oct 27 '17 at 13:17
  • And how do you plan to start this build? from the commandline or from VS? – rene Oct 27 '17 at 13:17
  • I am planning to start it from commandline – GenZiy Oct 27 '17 at 13:20
  • 1
    see these answers: https://stackoverflow.com/a/3623673/578411 – rene Oct 27 '17 at 13:20
  • yes, I am still referencing to $(MSBuildProjectDirectory), this is where GlobalAssemblyInfo.cs located. – GenZiy Oct 27 '17 at 13:29

1 Answers1

2

We generate a AssemblyInfo.cs file to put in all assembly attributes we need to define. You could do this on pre-build time if that suits you. There we define the AssemblyVersion, AssemblyFileVersion attribute and other related attributes.

Those properties will be used compiling the assembly.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325