TFS 2010 msbuild overwrites different versions of

2019-07-16 13:49发布

问题:

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?

回答1:

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.