question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Regression] .NET 6 SDK will no longer copy the netstandard facades to the publish directory for net461 apps

See original GitHub issue

cc: @dsplaisted @marcpopMSFT @andschwa @ericstj

Repro Steps

  1. Create a new netstandard lib
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

</Project>
  1. Create a new net461 Console app that references it:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\reproLib\reproLib.csproj" />
  </ItemGroup>

</Project>
  1. Publish the project with dotnet publish

Expected Because the net461 project is referencing a netstandard library, tooling should inject all of the netstandard facades onto the publish directory to ensure the application will be able to run as expected. This is what happens with .NET 5.0 and previous sdks.

Actual bin directory does get the facades injected, but the publish directory won’t when you use a 6.0 SDK, which means that if the app tries to run in a machine that only has .NET 461 installed, the app will likely crash at runtime.

Problem

I took a look and the issue here seems to be caused by this change which basically changed the way we calculate the items to be copied to the publish directory and added an additional filter to check if the ResolveCopyLocal item had the Private metadata set to false. When we are injecting the netstandard facades to resolveCopyLocal item, we explicitly set Private to false, which is why they are now all getting excludded from the publish directory. Here is where we set the metadata to false and the explanation of why we do it: https://github.com/dotnet/sdk/blob/203c2ac3eeb99d188d2b439c96f72f93b7b726fd/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/msbuildExtensions/Microsoft/Microsoft.NET.Build.Extensions/Microsoft.NET.Build.Extensions.NETFramework.targets#L91-L109

This regression has a potential of great impact, so we should consider how we can fix it before 6.0 ships, whether the solution is to not set Private item to false or if the solution is instead to change the new filter on the publish items.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
joperezrcommented, Aug 12, 2021

@dsplaisted is there an ETA for when this fix will land? I suppose that before shipping 6.0? If we don’t fix this in time I’m afraid a lot of customers will start hitting this as soon as we ship a VS that contains this SDK

1reaction
joperezrcommented, Jun 11, 2021

@andschwa I haven’t fully tested it, but you can try to see if the following target works for your needs:

  <Target Name="InjectNetStandardFacadesToPublishDirectory"
          BeforeTargets="ComputeResolvedFilesToPublishList"
          Condition="'@(_NETStandardLibraryNETFrameworkLib)' != ''">
    <ItemGroup>
      <_ResolvedCopyLocalPublishAssets Include="@(_NETStandardLibraryNETFrameworkLib)" 
                                      Condition="'%(_NETStandardLibraryNETFrameworkLib.FileName)' != 'netfx.force.conflicts'" />
    </ItemGroup>
  </Target>

I’m sure it is not perfect and it depends on internal items and targets so it is fragile and easy to get broken, but it may work while you wait for the final fix to make it to the SDK. From the testing I did, this should be injecting correctly all of the facades that your app requires into your publish directory.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MSBuild can't package .net 4.6.1 project w/ net core ...
NET 6 sdk, where a new filter that was added to the calculation of the publish files which caused our facades to no...
Read more >
NETSDK1045: The current .NET SDK does not support ...
Open the Solution Properties window (ctrl-click the solution in the Solution window and select Properties), select Build - General, and uncheck ...
Read more >
Building ASPNetCore 6.0 project: Microsoft packages not ...
I tried to rebuild again at this point and got a different error: MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found -...
Read more >
5x Lessons Learned from Migrating a Large Legacy to . ...
The answer was .NET Standard 2.0. With .NET Standard 2.0 the same DLL can be executed both : from within a Windows .NET...
Read more >
Microsoft.NET.Sdk.Publish doesn't copy files to ...
It creates a folder that I've specified as publishUrl in my publishing profile, but this folder is empty. From what I can see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found