Targetting different Frameworks using MSBuild gives problems with dependencies

一世执手 提交于 2019-12-03 09:05:12

I've been revisiting this problem again, since I do not like to have to manually change the csproj file. (When I change my reference, I must not forget to adapt the csproj file again, to set the Private node to true again).

So, I've been digging into MSDN, and I stumbled upon this:

ResolveAssemblyReference.TargetFrameworkDirectories Property

Remarks This property is required to determine the CopyLocal status for resulting items.

If this property is not specified, no resulting items will be have a CopyLocal value of true unless they explicitly have a Private metadata value of true on their source item.

So, this means that there is yet another possibility, and that is to set the TargetFrameworkDirectories of the ResolveAssemblyReference task. However, is there anybody out there who knows how to do this ?
I've been trying different things, but nothing seems to be working ...

I've tried this:

<ItemGroup>
    <TargetFrameworkDir Include="$(SystemRoot)\Microsoft.NET\Framework\v2.0.50727" />
</ItemGroup>

<PropertyGroup>
   <TargetDirsToUse>@(TargetFrameworkDir)</TargetDirsToUse>
</PropertyGroup>

<ResolveAssemblyReference TargetFrameworkDirectories="$(TargetDirsToUse)" />

But to no avail ... Maybe someone else knows how to do this, or has a golden tip. (I've been spending way to much time on this f*cking issue).

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.

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>

One question: what happens if you try to compile your 2.0 solution/projects inside VisualStudio? Are 3rd party references auto-copied or not?

It's odd that this would work for 3.5 and not for 2.0. I haven't done any parallel-building myself, but when I converted my projects from 2.0 to 3.5 all the 3rd party references were copied regardless of the .NET version.

BTW: I never reference 3rd party libraries from GAC (only those from Microsoft, and even not all of them). I always copy them to my lib directory structure, add them to the source control and reference them from there. Using assemblies from GAC is bad practice as far as I am concerned, since it represents an unnecessary dependency on a development machine setup.

Example of such a directory: http://code.google.com/p/projectpilot/source/browse/#svn/trunk/lib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!