C# 如何在 Visual Studio 中为项目引用设置“特定版本”属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/915712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:06:49  来源:igfitidea点击:

How to set "Specific Version" property for project references in Visual Studio

c#visual-studiovisual-studio-2008assembliesworkflow-foundation

提问by kay.herzam

I have got a Visual Studio Solution containing several projects and have set up the references between the projects as project references.

我有一个包含多个项目的 Visual Studio 解决方案,并将项目之间的引用设置为项目引用。

When a reference to an assembly is added, the references' properties contain a setting for

添加对程序集的引用时,引用的属性包含以下设置:

Specific Version = True|False

Specific Version = True|False

This property is missing for project references. How can it be set? I'd like my solution to load any available assembly (no matter what version) in the bin folder.

项目引用缺少此属性。怎么设置?我希望我的解决方案在 bin 文件夹中加载任何可用的程序集(无论是什么版本)。

I've had a problem when a workflow instance (Workflow Foundation) was deserialized and the dependencies were updated meanwhile.

当工作流实例 (Workflow Foundation) 被反序列化并同时更新依赖项时,我遇到了问题。

采纳答案by kay.herzam

I have found the solution to my problem. It's described pretty detailed here. The problem is not a matter of wrong project references, but more a de/serializing of workflow instances question.

我已经找到了解决我的问题的方法。它在这里描述得非常详细。问题不在于错误的项目引用,而在于工作流实例的反/序列化问题。

Thanks to everybody who tried to help.

感谢所有试图提供帮助的人。

回答by Joseph

I might be misunderstanding your question, but when you add a project reference, the project's assembly is always loaded into any project that references it when the project is built. Therefore, you'll always have the latest available assembly in the bin folder for that project. VS treats projects differently than other assemblies in that regard.

我可能误解了您的问题,但是当您添加项目引用时,该项目的程序集始终会加载到构建项目时引用它的任何项目中。因此,您将始终在该项目的 bin 文件夹中拥有最新的可用程序集。在这方面,VS 对待项目的方式与其他程序集不同。

回答by Juozas Kontvainis

You can add references to project output dlls instead of projects. Then you will be able to set Specific Version setting.

您可以添加对项目输出 dll 而不是项目的引用。然后您将能够设置特定版本设置。

回答by jerryjvl

I think the problem is that what you are asking is not possible directly with a project reference, I think that always implicitly turns into an 'explicit version', because of the nature of the link.

我认为问题在于您所问的问题无法直接通过项目引用实现,我认为由于链接的性质,这总是隐含地变成“显式版本”。

The way you coulddo this (calling the currently referenced project A, and the referencing project B):

可以这样做的方式(调用当前引用的项目 A 和引用的项目 B):

  • Have the project you want to reference in your solution, just like you do now with the project reference
  • Explicitly set the dependency chain so the 'referenced' project is built first
  • Build the referenced project A once first manually
  • Create an assembly reference in project B to the results from the build in project A
  • Set the assembly reference to 'Specific Version = false'
  • 在解决方案中包含要引用的项目,就像现在使用项目引用一样
  • 显式设置依赖链,以便首先构建“引用”项目
  • 首先手动构建引用的项目A一次
  • 在项目 B 中创建对项目 A 中构建结果的程序集引用
  • 将程序集引用设置为“特定版本 = false”

The build order (dependency) will guarantee that A is always built before B, and B will reference it from the binary output directory of A.

构建顺序(依赖)将保证 A 总是在 B 之前构建,并且 B 将从 A 的二进制输出目录中引用它。

(altho, it's a little brittle and I would not recommend it since it's easy to get wrong results if the settings are not all right, or the sun aligns with the stars wrong, or some such)

(不过,它有点脆弱,我不推荐它,因为如果设置不正确,或者太阳与星星对齐错误,或者诸如此类,很容易得到错误的结果)