有条件嵌入资源在Visual Studio(C#) [英] Conditionally embedding a resource in Visual Studio (C#)
问题描述
有没有办法有条件资源嵌入到一个.NET项目?即如果我定义INCLUDETHIS那么我想嵌入到DLL中的某个大文件,否则,我不希望它嵌入。我知道我可以做两个项目,要做到这一点,但我希望做这一切在一个项目中。使用该文件的code很容易调节了#如果INCLUDETHIS ... #ENDIF,但我甚至不想另有因为它包含敏感信息,仅供内部使用的DLL文件。
Is there a way to conditionally embed resources into a .NET project? I.e. if I have defined INCLUDETHIS then I want a certain large file embedded into the dll, otherwise I do not want it embedded. I know I can make two projects to do this, but I'm hoping to do it all in one project. The code that uses the file is easily conditioned with a #if INCLUDETHIS ... #endif, but I don't even want the file in the dll otherwise as it contains sensitive information and is only used internally.
推荐答案
这并获得成功,但我不得不手工编辑我的csproj用记事本+ +:
This did the trick, although I had to hand edit my csproj with Notepad++:
<Choose>
<When Condition=" '$(Configuration)'!='ReleaseExternal' And '$(Platform)'=='x86' ">
<ItemGroup>
<EmbeddedResource Include="file.dll">
<Link>Resources\Other\file.dll</Link>
</EmbeddedResource>
</ItemGroup>
</When>
</Choose>
这篇关于有条件嵌入资源在Visual Studio(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!