开发者

Dependency Definitions

I have a C# project that needs to compile as either x86, or x64, and reference different native assemblies depending on the architecture. I realize I could include them both and assign different alias's and in each file use a #if statement, but this is quite cumberso开发者_C百科me.

Is there any way to change a project's dependencies based on a Compiler condition?


The easiest way is to leverage build configurations. You need to do a bit of manual MSBuild (.csproj) file editing, but it works really nice:

This Link Has a great example of how to go about this.


That unfortunately is a PITA! I doubt that your #if statement would work (I reserve the right to be proven wrong), as each dependency needs to be a reference in the references section. The way I have worked around it is by editing each project's msbuild (.csproj) file, and creating a conditional ItemGroup that has the references for the appropriate platform.

<ItemGroup Condition="'$(Platform)' == 'x86'">
   <Reference Include="System" />
   <Reference Include="System.Data" />
   <Reference Include="System.Xml" />
</ItemGroup>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜