TFS 2010 msbuild 覆盖输出目录中引用库的不同版本

发布于 2024-12-05 22:43:55 字数 395 浏览 3 评论 0原文

我正在使用 TFS 2010 构建 Web 项目。该项目包含 Silverlight 客户端和 .NET/C# 服务器端。这两个(客户端和服务器)都引用一个第三方库,我们有 Silverlight 和 .NET 版本,但两个版本使用相同的名称。问题是指定了 outdir 属性的 msbuild 将所有库放入输出目录中的一个平面层次结构中,因此一个库会覆盖另一个库。

我知道一种解决方案是修改构建模板而不指定 outdir,但这会给构建模板的其他部分带来问题(我在单元测试方面遇到问题,并且我读到人们在将输出放入 _PublishedWebsites 时遇到问题)。

另一种解决方法是重命名该库,这样名称就不会冲突。但如果有很多这样的库,这将不是解决方案。

我想找到一些干净的解决方案。您知道如何解决这个问题的一些优雅的方法吗?

I'm building Web project using TFS 2010. The project contains Silverlight client and .NET/C# server side. Both of these (client and server) are referencing one 3rd party library for which we have Silverlight and .NET version, but both versions use the same name. The problem is that msbuild with outdir property specified puts all the libraries to one flat hierarchy in output directory so one library overwrites the other.

I know that one solution would be to modify build template and not specify outdir, but this brings problems with other parts of the build template (I had problem with unit tests and I read about people having problems with putting output to _PublishedWebsites).

Another workaround would be to rename that library/libraries so the names will not collide. But this will not be solution if there is a lot of such libraries.

I'd like to find some clean solution. Do you know about some elegant way how to solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哽咽笑 2024-12-12 22:43:55

根据 Microsoft 的说法,(至少)有三种引用程序集的方法:

  • 在 GAC 中安装程序集
  • 在应用程序配置中指定程序集
  • 或使用 AssemblyResolve 事件

GAC 在这里没有选项,因为您会遇到相同的问题(相同的名称) )。

使用 AssemblyResolve 事件然后使用 Assembly.LoadFrom 可能是一种实现方法,但恕我直言,

使用第二种提到的方法会更容易:在应用程序配置中指定程序集。在这里,您基本上像这样编辑 App.config:

<configuration>
   <runtime>
       <assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
         <probing privatePath=”bin;Silverlight;ParentFolder\SubFolder;”/>
      </assemblyBinding>
   </runtime>
</configuration>

并且应用程序将在指定目录中搜​​索程序集。

因此,您可以创建特定的文件夹(可能是“NET”和“Silverlight”等),将相应的程序集复制到该文件夹​​中,并如上所述在正确的文件夹中探测程序集。

考虑到当应用程序配置中未指定引用时,应用程序将查找与引用程序集相同的文件夹到具有引用程序集名称的文件夹中,您也可以简单地创建 2与相应应用程序同名的文件夹(如果它们称为“Client.exe”和“Server.exe”,请说“Client”和“Server”),并将正确的程序集复制到该文件夹​​中。在这种情况下,甚至不需要更改应用程序配置文件。

According to Microsoft there are (at least) three ways of referencing assemblies:

  • install the assembly in the GAC
  • specify the assembly in the application configuration
  • or use the AssemblyResolve Event

The GAC is no option here, as you would have the same problem (same names).

Using the AssemblyResolve Event and then use Assembly.LoadFrom would possibly a way of doing it, but easier would be imho ...

... to do it the second mentioned way: specify the assembly in the application configuration. Here you basically edit the App.config like so:

<configuration>
   <runtime>
       <assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
         <probing privatePath=”bin;Silverlight;ParentFolder\SubFolder;”/>
      </assemblyBinding>
   </runtime>
</configuration>

and the application will search for the assemblies in specified directories.

So, you could create specific folders (possibly "NET" and "Silverlight" or the like), copy the respective assembly into that folder and probe for the assembly in the proper folder as described above.

Considering that when no reference is specified in the application configuration the application will be looking into either the same folder as the referencing assembly or into a folder with the name of the referencing assembly, you could also simply create 2 folders with the same name as the respective application (say "Client" and "Server" if they are called "Client.exe" and "Server.exe") and copy the proper assembly into that folder. In that case there would not even be any need to change the application configuration file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文