Visual Studio参考和版本控制 - 它是如何工作的?

时间:2022-08-23 08:06:02

We have several common libs. Ideally we want them all to use the latest version of a dll even if they have been compiled against an older different version (assume the latest version is backward compatible)

我们有几个常见的库。理想情况下,我们希望他们都使用最新版本的DLL,即使它们是针对较旧的不同版本编译的(假设最新版本是向后兼容的)

e.g we have:

Project dll
Common controls dll
Logging dll
Database access dll

例如我们有:Project dll Common控件dll记录dll数据库访问dll

Project and common controls reference v2 of database dll. Logging however references v1.

项目和公共控件引用数据库dll的v2。然而,记录引用v1。

If different versions are referenced in different components how does VS pick which one to use?
Do we have to recompile v1 dll to use the latest database (v2) or can we get this to pick up automatically?
Is it possible to force a particular version to be used?

如果在不同的组件中引用了不同的版本,VS如何选择使用哪一个?我们是否必须重新编译v1 dll以使用最新的数据库(v2),或者我们可以自动获取它吗?是否可以强制使用特定版本?

Thanks,

Alex

4 个解决方案

#1


11  

By default, for versioned DLLs I believe VS will force an exact match. If you look in the properties of the reference, however, you'll find a property called "Specific Version". Set that to "false" and it will match later versions.

默认情况下,对于版本化的DLL,我相信VS会强制完全匹配。但是,如果查看引用的属性,则会找到名为“特定版本”的属性。将其设置为“false”,它将与更高版本匹配。

I don't have the full version of VS with me to find an appropriate MSDN link, unfortunately.

不幸的是,我没有完整版本的VS和我一起找到合适的MSDN链接。

In addition, you can use the assemblyBinding element in app.config.

此外,您可以在app.config中使用assemblyBinding元素。

#2


8  

There are actually two scenarios here - using strong names/GAC, or not using strong names.

这里实际上有两种情况 - 使用强名称/ GAC,或不使用强名称。

If you're using strong names, and installing the components into the GAC, then .Net will want to use the version of the component that the client was referencing when it was compiled. So in your example it would be quite possible for Project to reference database V2, while Logging referenced database V1, because the DLLs can be stored in parallel in the GAC. So if you actually want Logging to use V2 instead of V1, you will need to modify configuration files to say that "a reference to V1 should be pointed on to V2". There are different places to do this - app file, machine file etc.

如果您使用强名称,并将组件安装到GAC中,那么.Net将希望使用客户端在编译时引用的组件版本。因此,在您的示例中,Project很可能引用数据库V2,而Logging引用数据库V1,因为DLL可以并行存储在GAC中。因此,如果您确实希望Logging使用V2而不是V1,则需要修改配置文件以表示“应将V1的引用指向V2”。有不同的地方可以做到这一点 - 应用程序文件,机器文件等。

If you're not using strong names, then .Net will by default use the version of the DLL that's in the same folder as the client. So suppose you deploy Project, CommonControls and Logging in the same folder as database V2. Then even if Logging was built against database V1, it will attempt to use the component in the same folder, ie database V2. As long as V2 can supply the same public classes and methods that Logging wants to use, it will work fine.

如果您没有使用强名称,那么.Net将默认使用与客户端位于同一文件夹中的DLL版本。因此,假设您将Project,CommonControls和Logging部署在与数据库V2相同的文件夹中。然后,即使Logging是针对数据库V1构建的,它也会尝试使用同一文件夹中的组件,即数据库V2。只要V2可以提供Logging想要使用的相同公共类和方法,它就可以正常工作。

In my environment - where all our applications are internal - we don't use the GAC. We just deploy all the files that the application needs into a single folder. When you have a lot of common components, it would just be a nightmare to keep the configuration files in synch.

在我的环境中 - 我们的所有应用程序都是内部的 - 我们不使用GAC。我们只需将应用程序所需的所有文件部署到一个文件夹中。当你有很多常见的组件时,保持配置文件同步只是一场噩梦。

This is all very different to COM, where all applications picked up the currently registered copy of the DLL (assuming V1 and V2 were binary compatible).

这与COM完全不同,其中所有应用程序都获取了当前注册的DLL副本(假设V1和V2是二进制兼容的)。

#3


5  

I came across this site which has a couple of suggestions: http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/

我遇到了这个网站,其中有几条建议:http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/

To get a specific version apparently you have to edit web.config or app.config?

要显示特定版本,您必须编辑web.config或app.config?

"Finally, take a look at your csproj file using notepad (or unload the project in Visual Studio to be able to open it as text). When you add references using Visual Studio you will get a assembly reference with both version number and public key and this can give you some trouble when you upgrade a vendor assembly to a newer version."
http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/

“最后,使用记事本查看你的csproj文件(或者在Visual Studio中卸载项目以便能够以文本形式打开它。)当你使用Visual Studio添加引用时,你将得到一个包含版本号和公钥的程序集引用当您将供应商程序集升级到更新版本时,这会给您带来一些麻烦。“ http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/

#4


1  

If you have the source, you could use project references instead of dll references. That way you would always get the latest.

如果您有源,则可以使用项目引用而不是dll引用。这样你就会得到最新的。

#1


11  

By default, for versioned DLLs I believe VS will force an exact match. If you look in the properties of the reference, however, you'll find a property called "Specific Version". Set that to "false" and it will match later versions.

默认情况下,对于版本化的DLL,我相信VS会强制完全匹配。但是,如果查看引用的属性,则会找到名为“特定版本”的属性。将其设置为“false”,它将与更高版本匹配。

I don't have the full version of VS with me to find an appropriate MSDN link, unfortunately.

不幸的是,我没有完整版本的VS和我一起找到合适的MSDN链接。

In addition, you can use the assemblyBinding element in app.config.

此外,您可以在app.config中使用assemblyBinding元素。

#2


8  

There are actually two scenarios here - using strong names/GAC, or not using strong names.

这里实际上有两种情况 - 使用强名称/ GAC,或不使用强名称。

If you're using strong names, and installing the components into the GAC, then .Net will want to use the version of the component that the client was referencing when it was compiled. So in your example it would be quite possible for Project to reference database V2, while Logging referenced database V1, because the DLLs can be stored in parallel in the GAC. So if you actually want Logging to use V2 instead of V1, you will need to modify configuration files to say that "a reference to V1 should be pointed on to V2". There are different places to do this - app file, machine file etc.

如果您使用强名称,并将组件安装到GAC中,那么.Net将希望使用客户端在编译时引用的组件版本。因此,在您的示例中,Project很可能引用数据库V2,而Logging引用数据库V1,因为DLL可以并行存储在GAC中。因此,如果您确实希望Logging使用V2而不是V1,则需要修改配置文件以表示“应将V1的引用指向V2”。有不同的地方可以做到这一点 - 应用程序文件,机器文件等。

If you're not using strong names, then .Net will by default use the version of the DLL that's in the same folder as the client. So suppose you deploy Project, CommonControls and Logging in the same folder as database V2. Then even if Logging was built against database V1, it will attempt to use the component in the same folder, ie database V2. As long as V2 can supply the same public classes and methods that Logging wants to use, it will work fine.

如果您没有使用强名称,那么.Net将默认使用与客户端位于同一文件夹中的DLL版本。因此,假设您将Project,CommonControls和Logging部署在与数据库V2相同的文件夹中。然后,即使Logging是针对数据库V1构建的,它也会尝试使用同一文件夹中的组件,即数据库V2。只要V2可以提供Logging想要使用的相同公共类和方法,它就可以正常工作。

In my environment - where all our applications are internal - we don't use the GAC. We just deploy all the files that the application needs into a single folder. When you have a lot of common components, it would just be a nightmare to keep the configuration files in synch.

在我的环境中 - 我们的所有应用程序都是内部的 - 我们不使用GAC。我们只需将应用程序所需的所有文件部署到一个文件夹中。当你有很多常见的组件时,保持配置文件同步只是一场噩梦。

This is all very different to COM, where all applications picked up the currently registered copy of the DLL (assuming V1 and V2 were binary compatible).

这与COM完全不同,其中所有应用程序都获取了当前注册的DLL副本(假设V1和V2是二进制兼容的)。

#3


5  

I came across this site which has a couple of suggestions: http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/

我遇到了这个网站,其中有几条建议:http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/

To get a specific version apparently you have to edit web.config or app.config?

要显示特定版本,您必须编辑web.config或app.config?

"Finally, take a look at your csproj file using notepad (or unload the project in Visual Studio to be able to open it as text). When you add references using Visual Studio you will get a assembly reference with both version number and public key and this can give you some trouble when you upgrade a vendor assembly to a newer version."
http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/

“最后,使用记事本查看你的csproj文件(或者在Visual Studio中卸载项目以便能够以文本形式打开它。)当你使用Visual Studio添加引用时,你将得到一个包含版本号和公钥的程序集引用当您将供应商程序集升级到更新版本时,这会给您带来一些麻烦。“ http://blog.fredrikhaglund.se/blog/2008/02/23/get-control-over-your-assembly-dependencies/

#4


1  

If you have the source, you could use project references instead of dll references. That way you would always get the latest.

如果您有源,则可以使用项目引用而不是dll引用。这样你就会得到最新的。