项目需求1:主程序需要引用一个资源项目,根据编译配置 Visual Stuido中的Configuration Manager的不同,选择引用不同的资源项目
可在项目文件.csproj中添加如下内容:
<!-- Conditional References: Add conditional references here -->
<ItemGroup>
<ProjectReference Include="..\..\TargetLanguages\TargetLanguageThai\TargetLanguageThai.csproj" Condition=" '$(ConfigurationName)' == 'Thai' ">
<Project>{7A3F6F20-D083-4B7C-8B17-8091CDE95E20}</Project>
<Name>TargetLanguageThai</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\TargetLanguages\TargetLanguageGermany\TargetLanguageGermany.csproj" Condition=" '$(ConfigurationName)' == 'Germany' ">
<Project>{0A9B26F6-87A0-4E51-8FDA-9CAE7C006649}</Project>
<Name>TargetLanguageGermany</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\TargetLanguages\TargetLanguagesSpanish\TargetLanguageSpanish.csproj" Condition=" '$(ConfigurationName)' == 'Spanish' ">
<Project>{DA4BE376-36BD-4AC1-9CBB-C800C2D2D680}</Project>
<Name>TargetLanguageSpanish</Name>
</ProjectReference>
</ItemGroup>
注意使用这种方式添加的项目引用,所有的项目引用都会出现在References目录下,但是在编译时,条件引用会起作用(注意下图的Output输出):
参考:http://stackoverflow.com/questions/16556813/visual-studio-project-how-to-include-a-project-reference-based-on-some-defineco
[更新 2013-12-23]
由于所有资源项目都被引用,在编译时会被全部编译,可以通过Configuration Manager进行设置,只编译需要的项目:
项目需求2: 使用项目属性中的Post-Build 事件无法重命名输出文件,可以使用如下MSBuild task 实现文件复制到另一个目录同时重命名文件:
在.csproj中添加如下内容
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. -->
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
<Copy SourceFiles="$(OutDir)$(TargetName).xap" DestinationFiles="$(SolutionDir)APPBuild\$(ConfigurationName)\Store\$(TargetName)_$(ConfigurationName).xap" ContinueOnError="false" />
</Target>
参考:http://ardalis.com/how-to-move-or-rename-a-file-using-msbuild