dotnet / dotnet/sdk

`dotnet pack file.cs` produces NU5119 warning because all files in $(PublishDir) are included by default

Open
#52,587 2 comments 0 reactions 0 assignees View on GitHub
Area-run-file untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

When packing a file-based app into a tool via `dotnet pack app.cs` **after** the first execution (when there are already artifacts in the `./artifacts` directory) a `NU5119` warning is shown by the `Microsoft.NET.PackTools.targets` as the `.nupkg` file from the previous execution is included in the set of content to be included in the package:

```shell
➜ dotnet pack tool.cs
Restore complete (0.2s)
tool net10.0 succeeded (0.1s) → artifacts\tool\
tool net10.0 succeeded with 1 warning(s) (0.3s) → C:\Users\dedward\AppData\Local\Temp\dotnet\runfile\tool-99142bf9fe13acf84cb4e0c7781c0e5b02890f083423a8b8e8bd6464c0dce0bd\bin\release\tool.dll
C:\Program Files\dotnet\sdk\10.0.102\NuGet.Build.Tasks.Pack.targets(222,5): warning NU5119: File 'D:\scratch\FileBasedAppTool\artifacts\tool\tool.1.0.0.nupkg' was not added to the package. Files and folders starting with '.' or ending with '.nupkg' are excluded by default. To include this file, use -NoDefaultExcludes from the commandline
```

This is likely due to file-based apps defaulting both the `PublishDir` and the `PackageOutputPath` to the same location of `./artifacts/` and the `Microsoft.NET.PackTool.targets` grabbing everything in `PublishDir`:

```xml
<_PublishFiles Condition="'$(_ToolPackageShouldIncludeImplementation)' == 'true'" Include="$(PublishDir)/**/*" />
```

We should decide what the right approach for a fix here is, e.g. changing the default output path for packages produced from file-based apps, or modifying some properties/targets to ensure the nupkg is not included.

@baronfel what are your thoughts on changing `Microsoft.NET.PackTool.targets` to exclude `*.nupkg` files by default to avoid this warning?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.