MSBuild: How to make EmbeddedResource and file includes dependent on build configuration

If you use MSBuild (or Visual Studio) it’s sometimes helpful to make the files included in your project dependent on some external configuration (e.g. the environment or product version you’re targeting).

To do this for embedded resources, you can add a “Choose” block to the build file, like so:


  
    
      
        com.garysieling.resources.env-dev.xml
      
    
  

Note that the LogicalName is what actually gets put in the output assembly. If you specify a package prefix for the project, you will probably want to put this into the logical name, because it doesn’t get included automatically.

This assumes you’ve added build configurations to the project for the different options you want. This will take one of several files, and include them as the same name, no matter what environment you picked.

You can also do this with DLL references:


  False
  ..\libs\dotnet20\sp2007\Microsoft.SharePoint.dll
  False

Leave a Reply

Your email address will not be published. Required fields are marked *