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.

Using target runtime win-x64 include runtime assets which should be excluded

See original GitHub issue

Describe the bug

I have a nuget package with a .targets file to exclude a dependency from runtime. It works (i.e. dependency is not included) when publishing in Visual Studio with target runtime “portable” but dependency is included when target runtime is “win-x64”

The nuget package “NoRuntimeTest” (.nupkg not allowed, renamed to .zip NoRuntimeTest.1.0.0.zip) contain a NoRuntimeTest.targets file

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <PackageReference Update="NoRuntimeTest">
      <ExcludeAssets>runtime</ExcludeAssets>
    </PackageReference>
  </ItemGroup>
</Project>

When added to a new console app, Visual Studio shows it like this image i.e. the dll is correctly shown a compile time only dependency. (the Colors.Net.dll is just an example)

When publishing with target runtime “portable” the .deps.json looks like: (no dependency on Colors.Net.dll)

  "targets": {
    ".NETCoreApp,Version=v6.0": {
      "NoRuntimeTestApp/1.0.0": {
        "dependencies": {
          "NoRuntimeTest": "1.0.0"
        },
        "runtime": {
          "NoRuntimeTestApp.dll": {}
        }
      },
      "NoRuntimeTest/1.0.0": {}
    }
  },

but when publishing with target runtime “win-x64” the .deps.json file looks like: (a runtime dependency on Colors.Net.dll)

    ".NETCoreApp,Version=v6.0/win-x64": {
      "NoRuntimeTestApp/1.0.0": {
        "dependencies": {
          "NoRuntimeTest": "1.0.0"
        },
        "runtime": {
          "NoRuntimeTestApp.dll": {}
        }
      },
      "NoRuntimeTest/1.0.0": {
        "runtime": {
          "lib/net6.0/Colors.Net.dll": {
            "assemblyVersion": "1.1.0.0",
            "fileVersion": "1.1.0.0"
          }
        }
      }

To Reproduce

In Visual Studio:

  1. Create a new net 6.0 console application
  2. Add the attached “NoRuntimeTest” nuget package
  3. Build and publish to a folder with target runtime “portable”
  4. Build and publish to a folder with target runtime “win-x64”

I noted publishing from command line will always include the dependency!

  • dotnet new console --name …
  • dotnet add package NoRuntimeTest --source …
  • dotnet publish --output Portable --framework net6.0
  • dotnet publish --output Win64 --framework net6.0 --runtime win-x64 --no-self-contained

Also adding <excludeAssets>runtime</excludeAssets> to .csproj will always exclude the runtime dependency.

What is correct behavior? And if correct behavior is to include the runtime dependency, what should I do to exclude it? (I can’t use the developmentDependency tag in .nuspec because it is transitive)

Further technical details

dotnet --info dotnetinfo.txt VS 2022 17.0.2 on windows 10

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dsplaistedcommented, Feb 9, 2022

Modifying PackageReference items in .targets files that are included in packages is not supported. This is because the PackageReferences are an input to the NuGet restore process, and the .targets files from packages are not used until after NuGet restore is complete.

In Visual Studio, it can sometimes appear to work, but it is not recommended.

FYI @dotnet/nuget-team @nkolev92

0reactions
adrianm64commented, Feb 17, 2022

Thank you all for your input. I now know how to solve my problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core Application (.NET Framework) for Windows ...
I have a .net core application pointing to .net framework 4.6.1 in ... normal (target runtime was win7-x64) but that was enough for...
Read more >
dotnet publish command - .NET CLI
Publishes the .NET runtime with your application so the runtime doesn't need to be installed on the target machine. Default is true if...
Read more >
Unable to publish using target framework netcore3.1 and ...
I have desktop WPF app written in C# and using NetCore3.1. When I try to publish it to a folder, using target runtime...
Read more >
dotnet build command - .NET CLI
Publishes the .NET runtime with the application so the runtime doesn't need to be installed on the target machine. The default is true...
Read more >
Are you using AnyCPU or do you build for fixed targets?
I am mainly asking this, as I do have some code in C++ DLLs and I wonder if I should supply a 32...
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