{"id":4765,"date":"2016-07-22T21:13:39","date_gmt":"2016-07-22T21:13:39","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=4765"},"modified":"2016-07-22T21:13:39","modified_gmt":"2016-07-22T21:13:39","slug":"msbuild-make-embeddedresource-dependent-build-configuration","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/msbuild-make-embeddedresource-dependent-build-configuration\/","title":{"rendered":"MSBuild: How to make EmbeddedResource and file includes dependent on build configuration"},"content":{"rendered":"<p>If you use MSBuild (or Visual Studio) it&#8217;s sometimes helpful to make the files included in your project dependent on some external configuration (e.g. the environment or product version you&#8217;re targeting).<\/p>\n<p>To do this for embedded resources, you can add a &#8220;Choose&#8221; block to the build file, like so:<\/p>\n<pre lang=\"xml\">\n<Choose>\n  <When Condition=\"'$(Configuration)'=='dev-opt' OR '$(Configuration)'=='dev-dbg'\">\n    <ItemGroup>\n      <EmbeddedResource Include=\"resources\\env.xml\">\n        <LogicalName>com.garysieling.resources.env-dev.xml<\/LogicalName>\n      <\/EmbeddedResource>\n    <\/ItemGroup>\n  <\/When>\n<\/Choose>\n<\/pre>\n<p>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&#8217;t get included automatically.<\/p>\n<p>This assumes you&#8217;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.<\/p>\n<p>You can also do this with DLL references:<\/p>\n<pre lang=\"xml\">\n<Reference Include=\"Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL\" Condition=\"'$(Configuration)'=='dev-opt' OR '$(Configuration)'=='dev-dbg'\">\n  <SpecificVersion>False<\/SpecificVersion>\n  <HintPath>..\\libs\\dotnet20\\sp2007\\Microsoft.SharePoint.dll<\/HintPath>\n  <Private>False<\/Private>\n<\/Reference>\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How to make Visual Studio projects conditionally include files or DLL references, based on the build configuration<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[372],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4765"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=4765"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4765\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=4765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=4765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=4765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}