Does Msbuild recognise any build configurations other than DEBUG|RELEASE

后端 未结 4 668
臣服心动
臣服心动 2021-01-03 20:49

I created a configuration named Test via Visual Studio which currently just takes all of DEBUG settings, however I employ compiler conditions to determine some specific acti

相关标签:
4条回答
  • 2021-01-03 21:29

    Sure, you can have as many custom build configurations as you want to define. See this related question for how the setup might look.

    How to conditionally deploy an app.config based on build configuration?

    0 讨论(0)
  • 2021-01-03 21:32

    Normally what I do to have Release and Debug both build from a single MSBuild script is:

    <PropertyGroup Condition="'$(Configuration)'==''">
      <Configuration>Debug;Release</Configuration>
    </PropertyGroup>
    

    Then add this but of MSBuild secret sauce:

       <Target Name="configurations">
         <CreateItem Include="$(Configuration)">
           <Output TaskParameter="Include" ItemName="Configuration" />
         </CreateItem>
       </Target>
    

    And then for each target do something like this:

      <Target Name="Compile" DependsOnTargets="configurations" Inputs="@(Configuration)" Outputs="target\%(Configuration.FileName)">
        <MSBuild Projects="@(MyProjects)" Targets="Build" Properties="Configuration=%(Configuration.Identity);WarningLevel=1" />
      </Target>
    
    0 讨论(0)
  • 2021-01-03 21:48

    I haven't done much with defining an MSBUILD configuration file but I have done builds of different configurations using a batch file like this

    msbuild /v:n /p:Configuration=Release "Capture.sln" 
    msbuild /v:n /p:Configuration=ReleaseNoUploads "Capture.sln" 
    

    I defined the ReleaseNoUploads configuration inside Visual Studio.

    Here's what I had to do for that (this is Visual Studio 2005):

    • Open the Tools:Options menu, go to the Projects and Solutions:General option, and check Show advanced build configurations.
    • From there, go to the Build:Configuration Manager menu
    • In the dialog that pops up, click on the Active solution configuration pulldown and click <New...> to create a new build configuration.
    0 讨论(0)
  • 2021-01-03 21:48

    Note that when 'inside visual studio', the $(Configuration) and $(Platform) are always set by VS using the Configuration Manager stuff in the dropdowns at the top. Whereas if you want to set these values using msbuild from the command line, you must pass in the values explicitly (as in @MarkBiek's answer).

    (Most VS project templates will 'default in' a value for Configuration/Platform, so that you can use the command-line MSBuild without specifying these values explicitly. This is good, but makes these two useful/common properties appear a little more magical/weird than they actually are.)

    0 讨论(0)
提交回复
热议问题