[Regression] .NET 6 SDK will no longer copy the netstandard facades to the publish directory for net461 apps
See original GitHub issuecc: @dsplaisted @marcpopMSFT @andschwa @ericstj
Repro Steps
- Create a new netstandard lib
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
- 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>
- 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:
- Created 2 years ago
- Reactions:2
- Comments:11 (10 by maintainers)
@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
@andschwa I haven’t fully tested it, but you can try to see if the following target works for your needs:
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.