The calculated value of const is constantly constructed for

When updating our incremental build program, which runs during the pre-build event, I noticed a potential problem that could cause a lot of problems. When creating the application, BuildInfo.cs is successfully updated for the first time and all const values ​​are calculated. Each subsequent assembly and successful execution of the preliminary assembly event updates the correct file (as indicated below), but each calculated const value is out of date from the last assembly.

 // In externally modified file BuildInfo.cs which is updated by our pre-build // tool to update the version information and produce new consts. namespace ConstProblem.Properties { static class BuildInfo { internal const string AssemblyVersionString = "1.1.0.0"; internal const string BuildDate = "2012-11-07T08:52:32.5480259-07:00"; internal const string FileVersionString = "1.1.12312.852"; internal const string Full = "v1.1 (Build: 2012-11-07 08:52)"; internal const string Short = "1.1"; } } // Program.cs. Reproduces the problem for this question. namespace ConstProblem { class Program { const string UserAgent = "ConstProblem/" + Properties.BuildInfo.Short; static void Main() { System.Console.WriteLine(UserAgent); } } } 

As an example, an application was originally built using AssemblyVersionString at 1.0.0.0 . The above program was launched and compiled as expected. Increasing this to 1.1 and creating / running the application a second time, we will produce ConstProblem/1.0 as it is output and get it as a value

 // From the Immediate Window Properties.BuildInfo ConstProblem.Properties.BuildInfo base {object}: object AssemblyVersionString: "1.1.0.0" BuildDate: "2012-11-07T08:51:46.8404556-07:00" FileVersionString: "1.0.12312.851" Full: "v1.0 (Build: 2012-11-07 08:51)" Short: "1.0" 

As you can see, AssemblyVersionString was correctly updated 1.1.0.0 , but the rest of the calculated values ​​did not indicate. If I were to build and execute a third time (and increase to 1.2), they will be updated to the information given above.

I confirmed that the output file for the pre-build event displays all the information correctly and exits with status 0 to continue the build. I am at a loss why const is constantly building behind. The build utility is also what I wrote, and it just uses the template and replaces the contents of BuildInfo.cs if the file is uploaded.

Visual Studio 2010 Ultimate runs in my environment and compiles to .Net 4. I reproduced this in both console and web applications. I got the idea of ​​using const values ​​from comments in How to get the assembly version and version of your own assembly?

+4
source share
1 answer

It reads a successful build build from AssemblyInfo.cs. But it only increases by 1 after a successful build, so why are you always behind.

add [assembly: AssemblyVersion ("1.star.star.star")] to AssemblyInfo.cs (in solution / properties)

 ^ star = * (editor limitation) 
0
source

Source: https://habr.com/ru/post/1444613/


All Articles