有没有办法根据 Visual Studio 中的构建配置指定程序集引用?
我有一个项目,通过 API 为另一个应用程序添加了一些可扩展性。但是,我希望能够将同一个项目用于其应用程序的多个版本,因为大多数代码是相同的。
但是,应用程序的每个版本都需要引用该版本软件的正确程序集。他们将程序集加载到 GAC 中,因此即使我可以根据构建配置指定要使用的程序集的版本,我也可以。有没有办法从 VS 内部执行此操作,或者我是否需要外部构建工具?
I have a project that adds some extensibility to another application through their API. However, I want to be able to use the same project for multiple versions of their application, because most of the code is the same.
However, each version of the application requires a reference to the proper assembly for that version of the software. They load their assemblies into the GAC, so even if I could specify the version of the assembly to use based on build configuration I would be fine. Is there a way to do this from inside of VS or do I need an external build tool?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一种方法可以做到这一点,但您必须手动编辑项目文件。项目文件的许多元素(包括引用元素)中都可以应用一个
Condition
属性。您可以将这些添加到引用中以指定何时应使用引用:
然后定义多个构建配置(
V1
、V2
、V3
)每个参考将仅包含在相关选择的构建配置中。将其与代码中的条件编译符号和
#if
语句结合起来,您应该能够执行您想要的操作。如果执行此操作,需要注意的一点是,Visual Studio 很容易从项目文件中删除条件属性。
There is a way to do this, but you will have to hand edit your project files. The project files can have a
Condition
attribute applied to them in many of the elements, including the one for references.You can add these to your references to specify when the reference should be used:
You then define several build configurations (
V1
,V2
,V3
) and each reference will be included only in the relevant chosen build configuration.Combine this with conditional compilation symbols and
#if
statements in your code and you should be able to do what you want.A thing to be careful of if you do this is that it is easy to have Visual Studio remove the conditional attributes from the project file.
您可以使用以下属性替换提示路径:
$(Configuration) 相当于发布/调试或您拥有的任何其他配置。
$(Platform) 相当于 x86/x64/Any CPU
如果您的配置包括 Any CPU 那么您需要在 $(Configuration) 两边加上单引号
另请参阅 adrianbanks 引用的条件选项
You can replace the hint path with the properties:
$(Configuration) is equivalent to Release/Debug or whatever other configuration you have.
$(Platform) is equivalent to x86/x64/Any CPU
If your configuration includes Any CPU then you will need to put single quotes around $(Configuration)
Also refer to the condition options referenced by adrianbanks