What's the simple/idiomatic way of passing a value using msbuild /p:MyValue=Foo
at compile time, and using it at run time?
The resulting program looks like this
System.Console.WriteLine($"Value is '{Something.MyValue}'");
And if it is built with
msbuild /p:MyValue=Foo
then the output is
Value is 'Foo'
And if it is compiled without the parameter then the output is
Value is ''
The requirements are
- If the value is not passed, the compilation should still succeed, and the value should be e.g. null for a string.
- It must have no detrimental effect on up2date checks for the csproj.
- Ideally it should be something simpler than hand-rolling an msbuild task to dump a generated g.cs file into the obj directory. That has too many moving parts wrt. stale values and so on.
- Has to be portable between net6+ and net48