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.

Dependent .deps.json file not published when a package with PrivateAssets=all is included

See original GitHub issue

Scenario: Project A uses Project B via ProjectReference Project B includes package C via PackageReference (in this case, NSwag.MSBUILD v13.17.0) PackageReference (automatically added like that using the nuget package manager) is added in the following manner:

		<PackageReference Include="NSwag.MSBuild" Version="13.17.0">
			<PrivateAssets>all</PrivateAssets>
			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
		</PackageReference>

Both project A & Project B are console applications, .net6

Build area: Only Project A is built using the following command:

dotnet publish -c Release

Expected result:

  • Both projects A & B will be sent to output directory, and both files should arrive:
  • ProjectA.deps.json
  • ProjectB.deps.json
  • ProjectA.runtimeconfig.json
  • ProjectB.runtimeconfig.json

Actual result:

  • Both projects A & B are sent to output directory
  • ProjectA.deps.json
  • ProjectB.deps.json <-- file missing
  • ProjectA.runtimeconfig.json
  • ProjectB.runtimeconfig.json

Workaround: Remove PrivateAssets=all e.g.

		<PackageReference Include="NSwag.MSBuild" Version="13.17.0">
			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
		</PackageReference>

I’m attaching 2 verbose publishes:

  1. PrivateAsset = all
  2. PrivateAsset removed

Project A = Press.Host.BackupAndRestoreDev Project B = Press.Host.BackupAndRestore

I tried to find differences, this is what I presume is the issue:

6.706   2:9>Target "_ComputeUseBuildDependencyFile: (TargetId:407)" in file "C:\Program Files\dotnet\sdk\7.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets" from project "c:\WorkSpaces\OCB3\pc\Src\Press\Host\BackupAndRestore\Press.Host.BackupAndRestore.csproj" (target "AddDepsJsonAndRuntimeConfigToPublishItemsForReferencingProjects" depends on it):
                   Set Property: _UseBuildDependencyFile=true
14:40:56.706   2:9>Done building target "_ComputeUseBuildDependencyFile" in project "Press.Host.BackupAndRestore.csproj".: (TargetId:407)
14:40:56.706   2:9>Target "AddDepsJsonAndRuntimeConfigToPublishItemsForReferencingProjects: (TargetId:408)" in file "C:\Program Files\dotnet\sdk\7.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets" from project "c:\WorkSpaces\OCB3\pc\Src\Press\Host\BackupAndRestore\Press.Host.BackupAndRestore.csproj" (target **"GetCopyToPublishDirectoryItems" depends on it):
                   Added Item(s): 
                       AllPublishItemsFullPathWithTargetPath=
                           c:\WorkSpaces\OCB3\Press\Press.Host.BackupAndRestore.deps.json
                                   CopyToPublishDirectory=PreserveNewest
                                   TargetPath=Press.Host.BackupAndRestore.deps.json**

Doesn’t exists with PrivateAssets = all is written.

MissingDepsFile.zip ValidDepsFile.zip

Issue Analytics

  • State:open
  • Created 8 months ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
christianduerselencommented, Apr 26, 2023

As a workaround we’re using the following target which can be used in a csproj or Directory.Build.targets file. The target copies all deps.json files from the build output (where they are deployed to) the publish output.

<!-- Copy *.deps.json files from build output to publish output (workaround for https://github.com/dotnet/sdk/issues/29974) -->
<Target Name="CopyDependencyJsonFiles" AfterTargets="Publish">
  <ItemGroup>
    <DepsJsonFiles Include="$(OutputPath)*.deps.json" />
  </ItemGroup>
  <Copy SourceFiles="@(DepsJsonFiles)" DestinationFolder="$(PublishDir)" />
</Target>
0reactions
christianduerselencommented, Apr 26, 2023

We’re also running into this problem when trying to combine publish output from multiple projects. Since we’re using Nerdbank.GitVersioning having PrivateAssets=all as a PackageReference property is crucial since some projects are also provided as nuget-packages.

@baronfel is the minimal repo sufficient to triage this issue? While not a lot of people will have this kind of setup with one executable referencing another, this is hopefully something to easily isolate and fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NET CLI tool contains deps.json with development ...
The deps. json contains all dev dependencies and does not make sense for NET tools. The solution was to disable the generation of...
Read more >
PackageReference in project files - NuGet
When developmentDependency is set to true in a .nuspec file, this marks a package as a development-only dependency, which prevents the package ......
Read more >
Deep-dive into .NET Core primitives: deps.json ...
The deps.json file is a dependencies manifest. It can be used to configure dynamic linking to assemblies that come from packages. As mentioned ......
Read more >
How to generate runtimeconfig.json\deps. ...
Net Core 2.1 library. It has a runnable dependency - .Net Gateway, which I need to start first. However dotnet publish generates .runtimeconfig....
Read more >
Problem with dependencies after publishing winforms ...
Data.SqlClient, Version=4.5.0.0" occurs because the .deps.json file is included by default . If I manually delete the .deps.
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