Using MSBuild to Build Multiple Configurations

后端 未结 3 1311
太阳男子
太阳男子 2020-12-05 05:01

I\'m trying to edit my project file to enable me to have a project that builds multiple build configs at once. I\'ve done this using a batching approach and using the MSBuil

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 05:48

    It is important to realize that when you use a "MSBuild" task, a new child MSBuild process will be started. The implication of this is that any items and properties you define in the parent MSBuild process will not be automatically passed to/visible from the child MSBuild process unless you explicitely pass them via Properties attribute on MSBuild element (as in ).

    To answer your question, I wrote the following self-contained example that runs a child MSBuild project for all the specified configurations:

    1. First, create a directory for your MSBuild experiment (for example I used C:\temp\msbuildtest)

    2. In this directory, create the first file, main.proj:

      
          
              
              
          
          
          
              
          
      
      
    3. In the same directory, create the second file, child.proj (in your case this would be the actual C# project you're trying to build, but because I'm trying to illustrate my point, I am using a simple child project that instead of running C# compiler just prints values of properties :-) )

      
          
              
          
      
      
    4. Now you can run the example. First the default, if you don't explicitly specify configurations to build:

      C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild main.proj
      > (cut the noise)
      > Build:
      >   Building configuration Debug with output path C:\temp_c\d\bin\Debug
      

      And then explicitly specified multiple configurations:

      C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild main.proj /property:Config=Debug+Release+Staging+Production
      > (cut the noise)
      > Build:
      >   Building configuration Debug with output path C:\temp_c\d\bin\Debug
      > Build:
      >   Building configuration Release with output path C:\temp_c\d\bin\Release
      > Build:
      >   Building configuration Staging with output path C:\temp_c\d\bin\Staging
      > Build:
      >   Building configuration Production with output path C:\temp_c\d\bin\Production
      

    You should be able to adapt this technique to your situation.

提交回复
热议问题