Reputation: 37
So, i don't know if i was completely clear in my question but what I'm trying to do is a simple concept: i want to while compiling a c# windows forms application a variable X assume a value i wont know. But EVERY time i execute the application without compiling it again, this value is the same (but you don't know). So what I'm asking is if exist the possibility to compile something that you don't know which value will be. The application will use this same variable with the same value each time, but every time you compile the application again, this variable would change.
I'm trying to implement a security algorithm that will be different for each distribution of my application, but i want to do this in a automatic way without changing manual paramters for each release of my application.
A simple example of what i mean:
Upvotes: 3
Views: 1114
Reputation: 7625
The C# compiler emits a unique (random) ModuleVersionId (Guid) in every build. This differs even when building from the exact same source.
You may be able to use that as a build token.
As Enigmativity kindly mentioned, you can get to that value using:
this.GetType().Assembly.ManifestModule.ModuleVersionId
Upvotes: 5
Reputation: 100527
You can generate source or resource at build time and include that value as part of such source.
Links: Displaying the build date shows how to create resource at build time, you can also check out MSBuild task reference to build more integrated solution.
Note that protection of such kind is very easy to circumvent...
Upvotes: 0