使用MSBuild定位不同的框架会给依赖项带来问题 [英] Targetting different Frameworks using MSBuild gives problems with dependencies

查看:120
本文介绍了使用MSBuild定位不同的框架会给依赖项带来问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小项目,我想拥有该项目的2个编译版本:

I have a little project, and I want to have 2 compiled versions of that project:

  • 针对.NET 2.0框架的人
  • 针对.NET 3.5框架的人

一切进展顺利;我已经将我的项目进行了持续集成(使用CC.NET),并且创建了2个CC.NET项目".每个目标框架都有一个项目.

All is going well; I've put my project under continuous integration (using CC.NET), and I've created 2 CC.NET 'projects'. One project for each target-framework.

我不会在(无关的)细节上过多介绍,但是我的解决方案是针对VS.NET中的.NET 3.5框架而设置的.

I won't go too much in (irrelevant) details, but my solution is set up to target the .NET 3.5 framework in VS.NET.

我有2个msbuild任务:

I have 2 msbuild-tasks:

  • 一个为该解决方案构建解决方案的任务 .NET 3.5(简单易用)
  • 一个为该解决方案构建解决方案的任务 .NET 2.0

  • one task that builds the solution for .NET 3.5 (simple and easy)
  • one task that builds the solution for .NET 2.0

在此任务中,我调用MSBuild,并指定TargetFrameworkVersion为v2.0.我还定义了一些其他构建条件(这样,在针对.NET2.0的程序集中就不会构建.NET3.5特定代码).

In this Task, I call MSBuild, and I specify that the TargetFrameworkVersion should be v2.0. I also define some additional build-conditions (so that .NET3.5 specific code is not built in the assembly targetting .NET2.0).

到目前为止,太好了.一切正常. 现在,问题是这样的:

So far, so good. Everything works fine. Now, the problem however is this:

我的解决方案有一些依赖性(对第三者程序集的引用).在VS.NET中,我已将这些依赖项的本地复制"设置为true. 当CC.NET生成我的.NET3.5版本的程序集时,第3方依赖关系确实复制到了我的输出目录中.

My solution has a few dependencies (references to 3rd party assemblies). In VS.NET, I've set 'copy local' to true for these dependencies. When CC.NET builds my .NET3.5 version of the assembly, the 3rd party dependencies are indeed copied to my output-directory.

但是,当CC.NET生成程序集的.NET2.0版本时,依赖项不会复制到我的输出目录中. (然后,这导致我的单元测试失败).

However, when CC.NET builds my .NET2.0 version of the assembly, the dependencies are not copied to my output-directory. (Then, this causes my unit-tests to fail).

我现在的问题是: 我如何对msbuild说在构建项目的.NET2.0版本时某些第三方引用必须本地复制? 或者,还有其他方法可以实现此目标,因为我不想在构建脚本中再次指定每个依赖项.我想这将很快成为维护的噩梦.

My question now is: How can I say to msbuild that certain of the 3rd party references have to be copied local when building my .NET2.0 version of my project ? Or, is there any other way to achieve this, since, I wouldn't like to specify every dependency once again in my build-script. This would quickly become a maintenance nightmare, I guess.

推荐答案

我已经能够通过确保不引用GAC中的程序集来解决此问题. 相反,我在项目中创建了一个"lib"目录,其中包含第三方程序集. 在我的解决方案中,我从那里引用了第三方程序集,并设置了副本local == True.

I've been able to solve this problem by making sure that I do not reference assemblies from the GAC. Instead, I've created a 'lib' directory in my project that contains the 3rd party assemblies. In my solution, I reference the 3rd party assemblies from there, and set copy local==True.

此外,还必须确保在csproj文件中,引用的程序集具有私有"标记,其值设置为true. 像这样:

Next to that, you must also make sure that in your csproj file, the referenced assemblies have a Private tag whose value is set to true. Like this:

<Reference Include="...">
   <SpecificVersion>False</SpecificVersion>
   <HintPath>...</HintPath>
   <Private>True</Private>
</Reference>

这篇关于使用MSBuild定位不同的框架会给依赖项带来问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆