Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect the dll versions based on the referenced .NET Framework version in a ProjectFile #19

Closed
forki opened this issue Sep 2, 2014 · 20 comments
Labels

Comments

@forki
Copy link
Member

forki commented Sep 2, 2014

At the moment we install the last framework version of a package in alphabetical order.
This is of course non-sense

@forki forki added the bug label Sep 2, 2014
@forki
Copy link
Member Author

forki commented Sep 3, 2014

We could use conditions like in https://github.com/fsprojects/fsharpx/blob/master/src/FSharpx.Core/FSharpx.Core.fsproj

<Reference Include="FSharp.Core" Condition="$(TargetFrameworkVersion) == 'v3.5'">
  <HintPath>..\..\lib\FSharp\Net20\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="FSharp.Core" Condition="'$(TargetFrameworkVersion)' == 'v4.0'">
  <HintPath>..\..\lib\FSharp\FSharp.Core.dll</HintPath>
</Reference>

@agross
Copy link
Contributor

agross commented Sep 3, 2014

Looks good. This would allow us to keep the projs untouched regardless of the developer switching the target framework version in VS.

@forki
Copy link
Member Author

forki commented Sep 3, 2014

Yes. We just need a mapping from foldername in nuget package net40 to Condition="'$(TargetFrameworkVersion)' == 'v4.0'">

and a strategy for defaults.

@agross
Copy link
Contributor

agross commented Sep 3, 2014

"Just" might get complicated with the + variants... Let's start simple and add more stuff as users report errors.

@forki
Copy link
Member Author

forki commented Sep 4, 2014

I close this. Let's open concrete issues with bugs.

@forki forki closed this as completed Sep 4, 2014
@agross
Copy link
Contributor

agross commented Sep 4, 2014

Castle.Core misses the net-40 reference (the package contains lib/net40-client)

    <Reference Include="Castle.Core" Condition="$(TargetFrameworkVersion) == 'v3.5'">
      <HintPath>..\..\packages\Castle.Core\lib\net35\Castle.Core.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Castle.Core" Condition="$(TargetFrameworkVersion) == 'v4.5'">
      <HintPath>..\..\packages\Castle.Core\lib\net45\Castle.Core.dll</HintPath>
      <Private>True</Private>
    </Reference>

Reference: https://nuget.codeplex.com/wikipage?title=Framework%20Profile%20Support

@agross
Copy link
Contributor

agross commented Sep 4, 2014

If the project is built against the client profile we can check that with TargetFrameworkProfile == 'Client'.

If there is only lib/net40-client nuget references these DLLs for both client and full profiles:

    <Reference Include="Castle.Core" Condition="$(TargetFrameworkVersion) == 'v4.0'">
      <HintPath>..\..\packages\Castle.Core\lib\net40-client\Castle.Core.dll</HintPath>
    </Reference>

If there is both lib/net40-client and lib/net40, we need to have

    <Reference Include="Castle.Windsor" Condition="$(TargetFrameworkVersion) == 'v4.0' And $(TargetFrameworkProfile) == 'Client' ">
      <HintPath>..\..\packages\Castle.Windsor\lib\net40-client\Castle.Windsor.dll</HintPath>
    </Reference>
    <Reference Include="Castle.Windsor" Condition="$(TargetFrameworkVersion) == 'v4.0' And $(TargetFrameworkProfile) == '' ">
      <HintPath>..\..\packages\Castle.Windsor\lib\net40\Castle.Windsor.dll</HintPath>
    </Reference>

@agross agross reopened this Sep 4, 2014
@agross
Copy link
Contributor

agross commented Sep 4, 2014

The existence of lib/net45 and lib/net451 need to be handled similarly. That is

  • lib/net45 alone is referenced from 4.5 and 4.5.1 projects,
  • lib/net45 and lib/net451 needs two references, one for each framework version.

@agross
Copy link
Contributor

agross commented Sep 4, 2014

Wow, it gets even more complicated. log4net 1.2.10.0 follows a different convention: it uses lib/<CLR version>.

log4net 2.0.3 on the other hand uses lib/net40-full and lib/net40-client. Seems like we can consider lib/net40-full to be equal to lib/net40.

http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#Common_Framework_and_Profile_Targeting_Examples

@agross
Copy link
Contributor

agross commented Sep 5, 2014

Some bugs with specific packages I use in my sample solution:

Castle.Core has lib/net40-client only (not lib/net40-full), so it applies to both "client" and "full" framework. Paket currently adds

    <Reference Include="Castle.Core" Condition="$(TargetFrameworkVersion) == 'v3.5'">
      <HintPath>..\..\packages\Castle.Core\lib\net35\Castle.Core.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Castle.Core" Condition="$(TargetFrameworkVersion) == 'v4.0' And $(TargetFrameworkProfile) == 'Client'">
      <HintPath>..\..\packages\Castle.Core\lib\net40-client\Castle.Core.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Castle.Core" Condition="$(TargetFrameworkVersion) == 'v4.5.1'">
      <HintPath>..\..\packages\Castle.Core\lib\net45\Castle.Core.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Castle.Core" Condition="$(TargetFrameworkVersion) == 'v4.5'">
      <HintPath>..\..\packages\Castle.Core\lib\net45\Castle.Core.dll</HintPath>
      <Private>True</Private>
    </Reference>

@agross
Copy link
Contributor

agross commented Sep 5, 2014

The (oldish) log4net 1.2.10 uses lib/x.y to denote the CLR version, not the TargetFrameworkVersion. NuGet vanilla adds a reference to lib/2.0, probably because it's the last subfolder.

    <Reference Include="log4net" Condition="$(TargetFrameworkVersion) == 'v1.0'">
      <HintPath>..\..\packages\log4net\lib\1.0\log4net.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="log4net" Condition="$(TargetFrameworkVersion) == 'v1.1'">
      <HintPath>..\..\packages\log4net\lib\1.1\log4net.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="log4net" Condition="$(TargetFrameworkVersion) == 'v2.0'">
      <HintPath>..\..\packages\log4net\lib\2.0\log4net.dll</HintPath>
      <Private>True</Private>
    </Reference>

(This is a .NET 4.0 project.)

forki added a commit that referenced this issue Sep 5, 2014
@agross
Copy link
Contributor

agross commented Sep 5, 2014

RestSharp 104.4.0 has versions for Silverlight and WP and lib/net35 that should be used for my .NET 4.0 project.

    <Reference Include="RestSharp" Condition="$(TargetFrameworkVersion) == 'v3.5'">
      <HintPath>..\..\packages\RestSharp\lib\net35\RestSharp.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="RestSharp.Silverlight">
      <HintPath>..\..\packages\RestSharp\lib\sl4\RestSharp.Silverlight.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="RestSharp.WindowsPhone">
      <HintPath>..\..\packages\RestSharp\lib\sl4-wp71\RestSharp.WindowsPhone.dll</HintPath>
      <Private>True</Private>
    </Reference>

@agross
Copy link
Contributor

agross commented Sep 5, 2014

Silverlight has $(TargetFrameworkIdentifier) == 'Silverlight' and $(SilverlightVersion). Standard .NET apps seem to have $(TargetFrameworkIdentifier) == '.NETFramework'.

@forki
Copy link
Member Author

forki commented Sep 5, 2014

TargetFrameworkIdentifier OMG

@forki
Copy link
Member Author

forki commented Sep 5, 2014

could you please add the "correct" XML tags for RestSharp?

@agross
Copy link
Contributor

agross commented Sep 5, 2014

This is nothing more than a best guess. MSBuild is broken on so many levels, who would have thought that? 👿

<Choose>
  <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework'">
    <ItemGroup>
      <Reference Include="RestSharp">
        <HintPath>..\..\packages\RestSharp\lib\net35\RestSharp.dll</HintPath>
        <Private>True</Private>
      </Reference>
    </ItemGroup>
  </When>
  <When Condition="$(TargetFrameworkIdentifier) == 'Silverlight' And $(SilverlightVersion) == 'v4.0'">
    <ItemGroup>
      <Reference Include="RestSharp.Silverlight">
        <HintPath>..\..\packages\RestSharp\lib\sl4\RestSharp.Silverlight.dll</HintPath>
        <Private>True</Private>
      </Reference>
    </ItemGroup>
  </When>
  <When Condition="$(TargetFrameworkIdentifier) == 'WindowsPhoneApp' And $(TargetPlatformVersion) == '7.1'">
    <ItemGroup>
      <Reference Include="RestSharp.WindowsPhone">
        <HintPath>..\..\packages\RestSharp\lib\sl4-wp71\RestSharp.WindowsPhone.dll</HintPath>
        <Private>True</Private>
      </Reference>
    </ItemGroup>
  </When>
</Choose>

@agross
Copy link
Contributor

agross commented Sep 5, 2014

Based on c:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ProjectTemplates\CSharp I have identified:

  • TargetFrameworkIdentifier
  • SilverlightVersion
  • TargetPlatformVersion
  • TargetPlatformIdentifier
  • TargetFrameworkProfile

.NET Framework

  • TargetFrameworkIdentifier = .NETFramework
  • TargetFrameworkVersion = vX.Y.Z

Silverlight

  • TargetFrameworkIdentifier = Silverlight
  • TargetFrameworkVersion = vX.Y.Z
  • SilverlightVersion = vX.Y.Z set to TargetFrameworkVersion in templates, doesn't make sense w.r.t. SL5

Windows Phone

  • TargetPlatformIdentifier = WindowsPhoneApp
  • TargetPlatformVersion = 8.1 for WP8.1 (don't have templates for other versions)

Windows Store

  • TargetPlatformIdentifier is unset, so probably = ''
  • TargetPlatformVersion = 8.1

Portable Class Libraries

  • TargetFrameworkIdentifier
  • TargetPlatformVersion
  • TargetPlatformIdentifier
  • TargetFrameworkProfile ...might all be set or not, thanks to a nice if/else in the template:

Either:

  • TargetPlatformIdentifier or TargetFrameworkProfile
    Or:
  • TargetPlatformVersion or TargetFrameworkVersion

@agross
Copy link
Contributor

agross commented Sep 8, 2014

Looks like a good reference, even if it's not my MS: http://blog.stephencleary.com/2012/05/framework-profiles-in-net.html

@forki
Copy link
Member Author

forki commented Sep 8, 2014

tumblr_inline_muzu5lckao1raprkq

@forki
Copy link
Member Author

forki commented Sep 9, 2014

anything open?

@forki forki closed this as completed Sep 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants