Home > other >  Visual Studio 2019 Preprocessor definition as a result of cmd/sript
Visual Studio 2019 Preprocessor definition as a result of cmd/sript

Time:03-16

How can i make a definition as a variable from an evaluated expression? I add in my c project ( Visual Studio 2019 ) in the Project->Configuration Properties-> C/C -> Command Line /D "__MYVAL__=$(python3 .\calc.py)" but i get errors "the expression cannot be evaluated". How can i do this in visual studio 2019 preprocessor on windows?

CodePudding user response:

So this is not actually a Visual Studio thing - this is one level deeper. Welcome to the relatively unknown world of MSBuild.

MSBuild is the backend build engine for Visual Studio. It handles all the elements of the build process, and is responsible for managing and evaluating properties of the build, executing targets, finding and building dependencies, etc.

If you actually dig into the details, you'll find that Visual Studio projects are really just MSBuild scripts.

Have a look at the official documentation on properties for MSBuild. Based on what I could read, it looks like you can add C# code directly into the value of a property, and MSBuild will execute that code to perform custom actions.

If that's not enough for your purposes, you could also create a custom MSBuild task, which will allow you to run any code you like during the build process.

Once you have a property defined for what you want (we'll call it MyProperty), you can reference it on the command line via:

/D __MYVAL__=$(MyProperty)

  • Related