1

I am totally new in building Visual Studio Project through a script, so feel free to correct me if you feel that my understanding about the process is incorrect.

I have a visual studio solution which consists of a Wpf.exe project and few class library projects.

Currently I am successfully building .sln file using script below

"%VS_IDE_DIR%devenv.com" "...Solution-File-Path.sln" /rebuild Release /useenv

Currently the Wpf.exe file gets the File Version and Product Version 1.0.0.0 which is the default specified in Publish -> Publish Version Property of Wpf project. enter image description here

I want to somehow set the File Version and Product Version through my script. How can I achieve that?

I have an environment variable which contains the Product Version and File Version, Basically I want to set value of Product Version and File Version equal to my environment variable.

Haris Hasan
  • 29,856
  • 10
  • 92
  • 122

2 Answers2

2

There's a simple way to do this. In the WPF project, open the Properties node and double-click AssemblyInfo.cs. The [assembly: AssemblyFileVersion] attribute sets the File Version number. Add this to set the Product Version number:

[assembly: AssemblyInformationalVersion("1.2.3.4")]

Doing this from the command line is only technically possible. You'd have to create the native file version resource and compile it with rc.exe. And use Project + Properties, Resource file option to tell the compiler to use the custom .res file produced by rc.exe. You'd need scripting to get the version resource updated. Given how easy it is to do this by editing AssemblyInfo.cs, I'd recommend you don't bother.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Any idea how can I modify `AssemblyInfo.cs` through command line without going through `MS Build`? `devenv.com` I am currently using is different from `MSBuild` right? – Haris Hasan May 30 '11 at 18:11
  • Write a little program that you can call from the command line. Notepad works fine too. – Hans Passant May 30 '11 at 18:14
1

You can add /p:ApplicationVersion=1.0.0.1 while running the ms build command. The version number specified will be the version number the project will use while compiling the exe.

Update:

I have added the following xml code inside the project tag to the project file of my solution.

<ItemGroup>
<Tokens Include="ApplicationVersion">
      <ReplacementValue>$(ApplicationVersion)</ReplacementValue>
      <Visible>false</Visible>
</Tokens>
 </ItemGroup>
reggie
  • 13,313
  • 13
  • 41
  • 57
  • When I run `"%VS_IDE_DIR%devenv.com" "...SolutionPath.sln" /rebuild Release /useenv /p:ApplicationVersion=1.0.0.1` It gives me error `Invalid Command Line. Unknown Switch : p:ApplicationVersion=1.0.0.1.` – Haris Hasan May 30 '11 at 14:46
  • Try `"%VS_IDE_DIR%devenv.com" "...SolutionPath.sln" /rebuild Release /useenv /ApplicationVersion 1.0.0.1`. Must be a syntax error. I have tested the same. – reggie May 30 '11 at 14:56
  • if your specifying parameter value, run `p:/ApplicationVersion=1.0.0.1`. if not, just add `/ApplicationVersion 1.0.0.1` Try them both. Doesn't matter what dll's you using since the main project file compiled is your wpf application – reggie May 30 '11 at 15:20
  • When I add `\p:ApplicationVersion=1.0.0.1` I get `Invalid Command Line. Unknown Switch : p:ApplicationVersion=1.0.0.1`. Just a reminder that my .sln consists of several dll + one wpf.exe project. I have added `Xml` part only in wpf project – Haris Hasan May 30 '11 at 15:21
  • when I add `/Application=1.0.0.1` I get `Invalid Command Line. Unknown Switch : ApplicationVersion=1.0.0.1` – Haris Hasan May 30 '11 at 15:22
  • Another option to debug will be specifying the project file instead of the solution file. – reggie May 30 '11 at 15:23
  • Okay. So Answer the following questions. -Whats the error when you add `/p:ApplicationVersion=1.0.0.1` -Whats the error when you add `ApplicationVersion=1.0.0.1` -Do you get an error if you specify the project file instead of the solution file? -Try the question 1 and question 2 while compiling the project file. In your above comment, you are using a backward slash, instead of a forward slash. – reggie May 30 '11 at 15:29
  • Even if I only build the `wpf.exe` project I get same error when I append `/p:ApplicationVersion=1.0.0.1` or `ApplicationVersion=1.0.0.1` at the end of my command. Without appending this, project and solution builds fine. btw I really appreciate your help. – Haris Hasan May 30 '11 at 15:31
  • When I do `/p:ApplicationVersion=1.0.0.1` I get `Invalid Command Line. Unknown Switch : p:ApplicationVersion=1.0.0.1.` when I do `/ApplicationVersion=1.0.0.1` I get `Invalid Command Line. Unknown Switch : ApplicationVersion=1.0.0.1.` – Haris Hasan May 30 '11 at 15:35
  • Are you sure `/ApplicationVersion` should work when these are the only switches available? http://msdn.microsoft.com/en-us/library/xee0c8y7(v=vs.80).aspx (I don't have much knowledge about it) – Haris Hasan May 30 '11 at 15:44
  • Last try. What about '/ApplicationVersion 1.0.0.1' without the equal to sign. I wonder what the problem could be here. However, I will be doing my research and will get back to you if I come across anything interesting. These are the switches that you can add. http://msdn.microsoft.com/en-us/library/ms164311.aspx In short, /p:ApplicationVersion=1.0.0.1 should work if you have added the xml in the project file and you are building the project file itself. – reggie May 30 '11 at 17:14
  • My bad, I was following the MsBuild Documentation to answer your question. :( – reggie May 30 '11 at 17:21