2

I am trying to set a C# variable (string) to be compiled during the call to msbuild using the "/p" argument:

msbuild.exe mysolution.sln -p:MyCustomProperty=MyCustomValue

However, I'm stuck on how to access this "MyCustomProperty" value (MyCustomValue) in C# code... I was hoping for something simple like using an Attribute like this:

[GetAProjectPropertyAttribute("MyCustomProperty")]
public string MyVariable = "";

But I don't know if such an attribute exists? Are C# project properties not accessible during the compile to set certain code statements?

Any help is appreciated!

Kyle Ross
  • 87
  • 9
  • There is no such attribute available. You can write that property values to configuration file during msbuild and c#code can read it from configuration file at runtime when program runs. – Chetan Dec 10 '20 at 01:42
  • @ChetanRanpariya, do you have an example of "writing that property value to configuration file during msbuild and C# code reading it from configuration file at runtime?" – Kyle Ross Dec 10 '20 at 01:57
  • You can use XmlUpdate task in your build script... to write data to XML file... https://stackoverflow.com/questions/5175160/xmlupdate-task-not-updating-my-xml-file – Chetan Dec 10 '20 at 03:47

0 Answers0