Targetting different Frameworks using MSBuild gives problems with dependencies

前端 未结 2 458
失恋的感觉
失恋的感觉 2021-02-11 06:27

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

  • one that is targetting the .NET 2.0 framework
  • one that is targetting the
相关标签:
2条回答
  • 2021-02-11 07:05

    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).

    0 讨论(0)
  • 2021-02-11 07:07

    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>
    
    0 讨论(0)
提交回复
热议问题