17

In my Post-build event I call a batch file and pass it the current build config.

C:\Dev\Project\Build\build.bat /$(Configuration)

This passes the Project configuration name to the build script.

Is there anyway to pass the current Solution configuration name?

misteraidan
  • 1,984
  • 4
  • 23
  • 31

3 Answers3

2

I created a VS2010 extension for this, it lets you use $(SolutionConfiguration) and $(SolutionPlaform). $(BuildMacro) build macros. You can download the source and build it yourself from here.

Showing some code, it's just about registering to UpdateSolution_Begin method of IVsUpdateSolutionEvents VS and setting some Environment.SetEnvironmentVariable() there.

        _IVsSolutionBuildManager = (IVsSolutionBuildManager)GetService<SVsSolutionBuildManager>();
        _UpdateSolutionEvents = new UpdateSolutionEvents(); // IVsUpdateSolutionEvents
        int hr;
        uint pdwCookie;
        hr = _IVsSolutionBuildManager.AdviseUpdateSolutionEvents(_UpdateSolutionEvents, out pdwCookie);
ceztko
  • 14,736
  • 5
  • 58
  • 73
  • Good extension, but are there anything for that build in Visual Studio 2019? – Fedor May 13 '21 at 15:34
  • 1
    Sorry, the extension is unmaintained and it's open for grab, if someone wants to maintain it. Honestly, I just recommend to inform VisualStudio devs you want this feature in [this](https://developercommunity.visualstudio.com/t/define-macro-for-solution-configuration-or-platfor/527259) and [this](https://github.com/dotnet/msbuild/issues/70) RFEs. – ceztko May 13 '21 at 19:54
1

Not directly. When you use Edit/Macros on a property field, the only configuration name listed is the one for the project that you already have.

You can, however, define your own macro. For each solution configuration, create a new property sheet, use the "User Macros" tab to define a macro whose name is "SolutionConfiguration" and whose value is the name of the configuration, then add this property sheet to the appropriate project configuration of every project in the solution.

If there's a better way I'd love to learn of it.

Brangdon
  • 627
  • 5
  • 7
  • Is it possible to create property sheet for solution configuration? I know that you can do it for project only, i.e. for project configuration. Can you add more details please. – 23W Jan 23 '22 at 20:02
0

There is property SolutionConfigurationContents witch is created by Msbulid during soluton file processing it contains solution configuration in it. When building from VS it will contains project (not solution) configuration.

Brans Ds
  • 4,039
  • 35
  • 64