Skip to content

PrivateAssets=all has different behavior than PrivateAssets=compile;build;buildTransitive.... #39465

Closed as not planned
@donnie-msft

Description

@donnie-msft

@EdLichtman commented on Wed, 06 Mar 2024 18:23:21 GMT

NuGet Product Used

dotnet.exe

Product Version

.NET SDK: Version: 8.0.101 Commit: 6eceda187b Workload version: 8.0.100-manifests.30fce108 Runtime Environment: OS Name: Windows OS Version: 10.0.17763 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.101\ .NET workloads installed: Workload version: 8.0.100-manifests.30fce108 There are no installed workloads to display. Host: Version: 8.0.1 Architecture: x64 Commit: bf5e279d92 .NET SDKs installed: 1.1.14 [C:\Program Files\dotnet\sdk] 6.0.408 [C:\Program Files\dotnet\sdk] 7.0.400 [C:\Program Files\dotnet\sdk] 8.0.101 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation] Environment variables: Not set global.json file: C:\Source\nia\core-team-deployment-solutions\src\Microservices\Nx.Etl\global.json Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download

Worked before?

Not certain

Impact

It's more difficult to complete my work

Repro Steps & Context

Open up my sample code (PrivateAssetsDemonstration - Final) and you'll see 3 libraries:

PrivateAssetsDemonstration
PrivateAssetsDemonstration.Abstractions
Consumer

PrivateAssetsDemonstration.Abstractions contains an Attribute that's used to annotate the Consumer Assembly.
PrivateAssetsDemonstration actually applies the attribute to the ConsumerAssembly

If you change open "Consumer.csproj" and modify the "TestingWithAll" property from true to false, and publish it, you'll be able to run the publish exe with no issue.

However, if you keep the "TestingWithAll" property as "true", and you publish it, and run the publish exe, you'll see the following error:

   ---> System.IO.FileNotFoundException: Could not load file or assembly 'PrivateAssetsDemonstration.Abstractions, Version=1.0.3.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
  File name: 'PrivateAssetsDemonstration.Abstractions, Version=1.0.3.0, Culture=neutral, PublicKeyToken=null'
     at System.ModuleHandle.ResolveType(QCallModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
     at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
     at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
     at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg)
     at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
     at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
     at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
     at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
     at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
     at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T](Assembly element)
     at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.ExecuteHostingStartups()
     --- End of inner exception stack trace ---

https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files
This document specifies that setting PrivateAssets="all" is equal to setting PrivateAssets to "compile;runtime;contentFiles;build;buildMultitargeting;buildTransitive;analyzers;native"

However, it seems there is a side effect that setting PrivateAssets="all" also sets the transitive runtime dependencies to private I guess?

PrivateAssetsDemonstration - Final.zip

Verbose Logs

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions