OutSorcerer / nuget-dependencies-of-netstandard-library-bug

This repository reproduces a bug with classic .NET application that references .NET Standard library with NuGet dependencies
0 stars 1 forks source link

Workaround solution #1

Open moh-hassan opened 7 years ago

moh-hassan commented 7 years ago

In visual studio 2017 RTM, As a workaround, i modified the the NetStandard project as multi-target:

               <TargetFrameworks>netstandard1.4;net461</TargetFrameworks>

Rebuild the solution and the referenced dll are copied to bin folder of the legacy console project and it's working fine. Have a look to that fork(develop): https://github.com/moh-hassan/nuget-dependencies-of-netstandard-library-bug

OutSorcerer commented 7 years ago

Hello. Thanks for another workaround. My personal workaround is to add <RestoreProjectStyle>PackageReference</RestoreProjectStyle> to a legacy project (ClassicConsoleApp in this case). Microsoft is aware of this issue and current milestone for its fix is NuGet 4.4: https://github.com/NuGet/Home/issues/4488 I will add this information to the README.md.

moh-hassan commented 7 years ago

Hello outSourcerer, i add as a separate propertygroup as given below :

  <PropertyGroup>
     <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
 </PropertyGroup>

but it has no effect. If it resolves the bug, Can you add a new commit with this modification Thanks

OutSorcerer commented 7 years ago

It should be added to the first <PropertyGroup>...</PropertyGroup> as in 89162e50ddd5f455e167badd6e38b115d3a3e316.

moh-hassan commented 7 years ago

I did, but also no effect. It seems it's no longer supported by vs 2017 RTM or msbuild.

OutSorcerer commented 7 years ago

I have just tested this workaround and legacy .NET application was build successfuly with .NET Standard lib and Newtonsoft.Json.dll copied into its bin folder. I have

Microsoft Visual Studio Professional 2017 
Version 15.2 (26430.14) Release
VisualStudio.15.Release/15.2.0+26430.14

with

Microsoft (R) Build Engine version 15.1.1012.6693
moh-hassan commented 7 years ago

So, I have to update vs 2017 RTM Currently vs 15.0.0 +26228.4 (without update) with Microsoft (R) Build Engine version 15.1.1012.6693
Thanks for help and support

Update: It's working after updating to VisualStudio.15.Release/15.2.0+26430.14

moh-hassan commented 7 years ago

I installed today vs 2017 Preview (Version 15.3.0 Preview 3.0) with msbuild (15.3.388.41745) It uses NuGet.Tools version: 4.3.0-preview4-4199 I confirm your finding.

Test result: Working: add RestoreProjectStyle to the legacy project.

          <RestoreProjectStyle>PackageReference</RestoreProjectStyle> 

It copy all Nuget packages and also SDK packages referenced by NetStandard library

Not Working: add PrivateAssets as described in https://github.com/NuGet/Home/issues/4488

     <PrivateAssets>All</PrivateAssets>

I hope the bug will be resolved in the next release of nuget

Update: I deleted all obj /bin folder and rebuild the solution for every test case.

colinbate commented 7 years ago

Yes, I believe the RestoreProjectStyle support requires 15.2 or above, and is not supported in 15.0 and 15.1.

moh-hassan commented 7 years ago

@colinbate, I find RestoreProjectStyle copy both referenced external Nuget Packages and also all SDK package of the Netstandard library to the bin folder, and I think it's supposed to copy only the external Nuget Packages. Is't right?

wwdenis commented 7 years ago

The multi-targeting workaround only works for classic CSPROJ but not for PCL (Xamarin). This issue will be fixed?

OutSorcerer commented 7 years ago

@wwdenis See my first message in this issue for another possible workaround and regaring the expected time of its fix see the link to the corresponding issue in NuGet repository. If both these workarounds do not work for you you have to apply less elegant one like referencing a NuGet package missing in output directory directly.

moh-hassan commented 7 years ago

PackageReference copy both referenced nuget packages and .Net standard SDK packages. If you want to remove the extra copied binaries, you can use a trimming tool. https://github.com/dotnet/standard/blob/master/Microsoft.Packaging.Tools.Trimming/docs/trimming.md , which is a tool to trim unnecessary binaries from the output. Reference: https://github.com/dotnet/standard/issues/415#issuecomment-314288712