-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
The dotnet store is incorrectly including BCL assemblies when targeting .NET Core 3.1 #10973
Comments
Friendly ping on this to get some attention. This is breaking some of our scenarios for .NET Core 3.1. |
This is a bummer. Prevents us from using 3.1 in some of our AWS Lambdas. Hoping there is an easy resolution/workaround for this issue. |
Wonder if the root cause is related to this issue dotnet/runtime#2836; Found the issue referenced in the code to handle an additional file being stored. https://github.com/dotnet/sdk/blob/master/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToStoreAProjectWithDependencies.cs#L92 From a quick look at different versions, this only seems to happen for Newtonsoft.Json versions < 11. Only major change that I initially see to cause this is that version 11 starts referencing |
This is a result of changes we made in .NET Core 3. We no longer use PackageReferences to represent .NET Core Framework. This is discussed here: dotnet/designs#50 The old version of NewtonSoft.Json has dependencies to packages which are part of .NET Core. Because we don't represent .NET Core as a PackageReference anymore, the The ideal fix to this would likely be NuGet/Home#7344, and possibly additional changes in Possible workarounds:
<Target Name="AddPackagesToPrune" AfterTargets="PrepforRestoreForComposeStore">
<ItemGroup>
<PackagesToPrune Include="Microsoft.CSharp" />
<PackagesToPrune Include="System.Collections" />
<PackagesToPrune Include="System.Diagnostics.Debug" />
<PackagesToPrune Include="System.Dynamic.Runtime" />
<PackagesToPrune Include="System.Globalization" />
<PackagesToPrune Include="System.IO" />
<PackagesToPrune Include="System.Linq" />
<PackagesToPrune Include="System.Linq.Expressions" />
<PackagesToPrune Include="System.ObjectModel" />
<PackagesToPrune Include="System.Reflection" />
<PackagesToPrune Include="System.Reflection.Extensions" />
<PackagesToPrune Include="System.Resources.ResourceManager" />
<PackagesToPrune Include="System.Runtime" />
<PackagesToPrune Include="System.Runtime.Extensions" />
<PackagesToPrune Include="System.Runtime.Serialization.Primitives" />
<PackagesToPrune Include="System.Text.Encoding" />
<PackagesToPrune Include="System.Text.Encoding.Extensions" />
<PackagesToPrune Include="System.Text.RegularExpressions" />
<PackagesToPrune Include="System.Threading" />
<PackagesToPrune Include="System.Threading.Tasks" />
<PackagesToPrune Include="System.Xml.ReaderWriter" />
<PackagesToPrune Include="System.Xml.XDocument" />
</ItemGroup>
<PropertyGroup>
<PackagesToPrune>$(PackagesToPrune);@(PackagesToPrune)</PackagesToPrune>
</PropertyGroup>
</Target> Note that if there is a |
Interesting. In my case I have the option to make a modifications to a copy of the inputted manifest and use that when calling |
@normj Could you update your library which depends on NewtonSoft.Json to depend on at least 11.0.1? That should help mitigate the issue. |
I can, but I can't control whether somebody uses our tool that relies |
@dsplaisted, do you see any issues with this type of workaround until NuGet/Home#7344 is resolved?
Am I missing any major aspect regarding this? |
@davidruhmann I think something like that could work, but mapping from the dependencies in the runtime folder to packages that should be excluded may not be simple. You have to consider not just the file name but the version number, and also map it to the right NuGet package. |
Appreciate the quick reply! Version did cross my mind, but wouldn't that just be for higher versioned references? Which, if I understand correctly, could still be resolved by the store consumer? Meaning the store would possibly be missing some elements, but not the flip side of including unnecessary elements. As for the naming of nuget packages to BCL components, are there many differences? I am thinking of this workaround in a scope of 80% success or something like that. If it can solve the majority of conflicts for the current time until NuGet/Home#7344 is complete; that should be good enough vs making the workaround too complex. Even if the other 20% result in failure, the original bloated store could still be used or fail the process entirely saying unsupported. |
@davidruhmann I must admit I have not patience for gardening, but pruning I did try. Initial manifest -> dotnet store -> look at resulting artifact.xml -> add the extraneous packages to prune list on initial manifest -> dotnet store again. What I found is that the Initial manifest: <Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.3" />
</ItemGroup>
</Project>
Output is: <StoreArtifacts>
<Package Id="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.3" />
<Package Id="Microsoft.CSharp" Version="4.3.0" />
<Package Id="Microsoft.IdentityModel.JsonWebTokens" Version="5.5.0" />
<Package Id="Microsoft.IdentityModel.Logging" Version="5.5.0" />
<Package Id="Microsoft.IdentityModel.Protocols" Version="5.5.0" />
<Package Id="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="5.5.0" />
<Package Id="Microsoft.IdentityModel.Tokens" Version="5.5.0" />
<Package Id="Newtonsoft.Json" Version="10.0.1" />
<Package Id="runtime.any.System.Collections" Version="4.3.0" />
<Package Id="runtime.any.System.Diagnostics.Tools" Version="4.3.0" />
<Package Id="runtime.any.System.Diagnostics.Tracing" Version="4.3.0" />
<Package Id="runtime.any.System.Globalization" Version="4.3.0" />
<Package Id="runtime.any.System.IO" Version="4.3.0" />
<Package Id="runtime.any.System.Reflection" Version="4.3.0" />
<Package Id="runtime.any.System.Reflection.Extensions" Version="4.3.0" />
<Package Id="runtime.any.System.Reflection.Primitives" Version="4.3.0" />
<Package Id="runtime.any.System.Resources.ResourceManager" Version="4.3.0" />
<Package Id="runtime.any.System.Runtime" Version="4.3.0" />
<Package Id="runtime.any.System.Runtime.Handles" Version="4.3.0" />
<Package Id="runtime.any.System.Runtime.InteropServices" Version="4.3.0" />
<Package Id="runtime.any.System.Text.Encoding" Version="4.3.0" />
<Package Id="runtime.any.System.Text.Encoding.Extensions" Version="4.3.0" />
<Package Id="runtime.any.System.Threading.Tasks" Version="4.3.0" />
<Package Id="runtime.unix.System.Diagnostics.Debug" Version="4.3.0" />
<Package Id="runtime.unix.System.IO.FileSystem" Version="4.3.0" />
<Package Id="runtime.unix.System.Private.Uri" Version="4.3.0" />
<Package Id="runtime.unix.System.Runtime.Extensions" Version="4.3.0" />
<Package Id="System.Buffers" Version="4.3.0" />
<Package Id="System.Collections.NonGeneric" Version="4.3.0" />
<Package Id="System.Collections.Specialized" Version="4.3.0" />
<Package Id="System.ComponentModel" Version="4.3.0" />
<Package Id="System.ComponentModel.Primitives" Version="4.3.0" />
<Package Id="System.ComponentModel.TypeConverter" Version="4.3.0" />
<Package Id="System.Dynamic.Runtime" Version="4.3.0" />
<Package Id="System.Globalization.Extensions" Version="4.3.0" />
<Package Id="System.IdentityModel.Tokens.Jwt" Version="5.5.0" />
<Package Id="System.IO.FileSystem.Primitives" Version="4.3.0" />
<Package Id="System.Linq" Version="4.3.0" />
<Package Id="System.Linq.Expressions" Version="4.3.0" />
<Package Id="System.ObjectModel" Version="4.3.0" />
<Package Id="System.Reflection.Emit" Version="4.3.0" />
<Package Id="System.Reflection.Emit.ILGeneration" Version="4.3.0" />
<Package Id="System.Reflection.Emit.Lightweight" Version="4.3.0" />
<Package Id="System.Reflection.TypeExtensions" Version="4.3.0" />
<Package Id="System.Runtime.Numerics" Version="4.3.0" />
<Package Id="System.Runtime.Serialization.Formatters" Version="4.3.0" />
<Package Id="System.Runtime.Serialization.Primitives" Version="4.3.0" />
<Package Id="System.Security.Cryptography.Cng" Version="4.5.0" />
<Package Id="System.Text.RegularExpressions" Version="4.3.0" />
<Package Id="System.Threading" Version="4.3.0" />
<Package Id="System.Threading.Tasks.Extensions" Version="4.3.0" />
<Package Id="System.Xml.ReaderWriter" Version="4.3.0" />
<Package Id="System.Xml.XDocument" Version="4.3.0" />
<Package Id="System.Xml.XmlDocument" Version="4.3.0" />
</StoreArtifacts> initial.xml with one package added to prune: <Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.3" />
</ItemGroup>
<Target Name="AddPackagesToPrune" AfterTargets="PrepforRestoreForComposeStore">
<ItemGroup>
<PackagesToPrune Include="Microsoft.CSharp" />
</ItemGroup>
<PropertyGroup>
<PackagesToPrune>$(PackagesToPrune);@(PackagesToPrune)</PackagesToPrune>
</PropertyGroup>
</Target>
</Project> Prune worked -- there are less packages in artifact.xml. Great. Now, if I do this: <Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.3" />
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="5.0.0" />
</ItemGroup>
<Target Name="AddPackagesToPrune" AfterTargets="PrepforRestoreForComposeStore">
<ItemGroup>
<PackagesToPrune Include="Microsoft.CSharp" />
</ItemGroup>
<PropertyGroup>
<PackagesToPrune>$(PackagesToPrune);@(PackagesToPrune)</PackagesToPrune>
</PropertyGroup>
</Target>
</Project> I will get |
@clearwaterstream Thanks for creating the proof of concept. I see, this error is because the Filter target is being run per dependency and the Amazon dependency is not pulling in Microsoft.CSharp. Have to step away, but wonder if we can inject in before the Filter target to dynamically build the prune list per dependency. Will take a look later but it will most likely hinge on how the FilterResolvedFiles target is written and if ResolvedFiles is accessible to a before target. |
We can probably fix the NullReferenceException in the 5.0 SDK if that would be a significant help. IE then it would be OK to specify packages to prune that aren't in the package graph. |
@davidruhmann you mentioned "... dynamically build the prune list per dependency." and @dsplaisted you mentioned "... specify packages to prune that aren't in the package graph". So would the prune list calculation logic know how to not add packages to the prune list that are legitimate dependencies? For example: <PackageReference Include="MySql.Data" Version="8.0.19" /> Would pull in (to name a few): <Package Id="SSH.NET" Version="2016.1.0" />
<Package Id="SshNet.Security.Cryptography" Version="1.2.0" />
<Package Id="BouncyCastle.NetCore" Version="1.8.3" />
<Package Id="Google.Protobuf" Version="3.6.1" /> Currently if I blindly take all the "extra" packages that are in the resultant |
@dsplaisted Yes, that would be nice. @clearwaterstream To clarify, the list of excluded libraries for the use case is limited to what is found in the framework runtime (the BCLs). Sub-depedencies would not be part of the exclusion list unless manually specified. Here is a working example excluding Microsoft.CSharp from artifact.xml; however the file still exists in the store. Instead of passing in <Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.3" />
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="5.0.0" />
</ItemGroup>
<Target Name="PruneBCLs" AfterTargets="ComputeFilesToStore">
<ItemGroup>
<BCLsToPrune Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<ResolvedPackagesPublished Remove="@(BCLsToPrune)" />
</ItemGroup>
</Target>
</Project> Now, in the case that @normj originally posted above; the BCLsToPrune list could be populated with the filenames found in the runtime directory. (e.g. /usr/local/share/dotnet/shared/Microsoft.NETCore.App/3.1.3) |
@dsplaisted Is there no way the NullReferenceException could be ported to the 3.1 SDK? We generally stick with LTS versions which means we wouldn't get a fix till .NET 6. |
@normj The NullReferenceException should be fixed in the 3.1.400 SDK release. |
@dsplaisted Great looking forward to it! |
I was in the process to give AWS Lambda layers with .NET Core a try and got stuck with the publish-layer command referencing this issue here. What are your current recommmendations for such a situation @normj ? Should we wait for 3.1.400 SDK to be released or should we try with TargetFramework=netcoreapp2.1 ? The latter seems not to work with the following dependencies:
|
@niklr For the Lambda side the ball is in my court now to update the Lambda tooling to use the work around added in 3.1.400. I hope to get to that soon just juggling a few things right now. I think the issue is still worth leaving open as I think the current fix in 3.1.400 is a work around that requires users of the |
Looking forward for this change. Any tentative timelines? |
@normj - Glad to see your contributions to the corresponding repositories this month. Can we expect anything soon? |
@dsplaisted - any news on when Verified version 3.1.302 still has the Null Reference Exception bug on @clearwaterstream's sample:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.3" />
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="5.0.0" />
</ItemGroup>
<Target Name="AddPackagesToPrune" AfterTargets="PrepforRestoreForComposeStore">
<ItemGroup>
<PackagesToPrune Include="Microsoft.CSharp" />
</ItemGroup>
<PropertyGroup>
<PackagesToPrune>$(PackagesToPrune);@(PackagesToPrune)</PackagesToPrune>
</PropertyGroup>
</Target>
</Project> console: > dotnet --version
3.1.302
> dotnet store --manifest initial.xml -f netcoreapp3.1 -o bin/dotnetcore/store -r linux-x64 --skip-optimization
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ComposeStore.targets(420,5): error MSB4018: The "FilterResolvedFiles" task failed unexpectedly. [C:\projects\sandbox\dotnetStoreBug\manifest.xml]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ComposeStore.targets(420,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [C:\projects\sandbox\dotnetStoreBug\manifest.xml]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ComposeStore.targets(420,5): error MSB4018: at Microsoft.NET.Build.Tasks.LockFileExtensions.GetTransitivePackagesList(LockFileTarget lockFileTarget, LockFileTargetLibrary package, IDictionary`2 libraryLookup) [C:\projects\sandbox\dotnetStoreBug\manifest.xml]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ComposeStore.targets(420,5): error MSB4018: at Microsoft.NET.Build.Tasks.ProjectContext.GetTransitiveList(String package) [C:\projects\sandbox\dotnetStoreBug\manifest.xml]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ComposeStore.targets(420,5): error MSB4018: at Microsoft.NET.Build.Tasks.FilterResolvedFiles.ExecuteCore() [C:\projects\sandbox\dotnetStoreBug\manifest.xml]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ComposeStore.targets(420,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute() [C:\projects\sandbox\dotnetStoreBug\manifest.xml]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ComposeStore.targets(420,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\projects\sandbox\dotnetStoreBug\manifest.xml]
C:\Program Files\dotnet\sdk\3.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ComposeStore.targets(420,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\projects\sandbox\dotnetStoreBug\manifest.xml]
|
@ppittle 3.1.400 will release together with Visual Studio 2019 version 16.7. I don't think we've announced when that will be, but you can see the previews we've released so far here: https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-preview |
@dsplaisted I've skimmed through the notes https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2019-mac-preview-relnotes and 3.1.400 is not mentioned there either. Do you happen to know if this may potentially make it into the 8.7 release of VS 4 Mac? |
@leecow Do you know if VS for Mac 8.7 will include .NET Core SDK 3.1.400? Thanks. |
I believe that's correct. @mrward to confirm. |
VS Mac 8.7 currently includes .NET 3.1.302. I expect VS Mac 8.7 will at some point include .NET 3.1.400 since Visual Studio 2019 16.7 will be doing so. |
As far as I can tell, 3.1.400 is not released. If it is, I don't see it here: https://dotnet.microsoft.com/download/dotnet-core/3.1 |
Hi @dsplaisted / @normj |
@bonjo It sounds like that message is coming from the |
@bonjo as @dsplaisted mentioned we (AWS) need to update the |
@normj I assume then that |
@bonjo You're in luck! It's open source as well, so you can build it locally with the required modification to unblock yourself. |
@bonjo correct we don't have a preview version as we haven't started the work yet. |
Whoever it may concern, |
@slavanap We've released a new patch. You can download 3.1.401 here: https://dotnet.microsoft.com/download/dotnet-core/3.1 |
@devssharma You need to post that over here: aws/aws-extensions-for-dotnet-cli#113 |
I have a PR out using the pruning workaround into the AWS Lambda tooling. aws/aws-extensions-for-dotnet-cli#144 @dsplaisted do you think there will ever be a better solution in the dotnet store command other then adding this pruning list? I hope so but if not then we can close this issue and people concern with the AWS use case should track the fix via the PR. |
Unfortunately I think it's unlikely that we'll fix this with a better solution. It would require NuGet/Home#7344, which I would like to see and would fix some other issues. However, it would be a major feature for NuGet, and probably only helps for cases where a .NET Core 1.x / .NET Standard 1.x package is referenced, which should happen less and less as time goes on. So it's probably not going to be worth prioritizing. |
Alright thanks for the pruning fix. That seems to work for our use case. |
Using the following store manifest that only includes Newtonsoft.Json
I execute the following command to create a store for .NET Core 2.1:
the store
artifact.xml
contains only Newtonsoft.Json as expected.But then creating the store for .NET Core 3.1 using the command:
Creates a store with a lot of runtime and system dlls which bloat the package store and also those assembles fail to the store optimization.
This change in behavior seems to make the
dotnet store
command a broken experience.@nguerrera We have talked about
dotnet store
in the past. Can you shed any light on why this is happening now?The text was updated successfully, but these errors were encountered: