dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.26k stars 9.96k forks source link

Project that uses Microsoft.NET.Sdk.Web copies packages.lock.json to output #55568

Closed flcdrg closed 1 month ago

flcdrg commented 4 months ago

Is there an existing issue for this?

Describe the bug

Given an ASP.NET web project where the csproj has Sdk="Microsoft.NET.Sdk.Web", then if that project uses a NuGet lockfile, then the lockfile is also copied to the output directory when the project is built.

Expected Behavior

packages.lock.json should not be copied to the output directory.

It isn't copied to the output directory for projects that use Microsoft.NET.Sdk

This may have the potential to confuse build pipeline caching tasks as they often use wildcards to locate packages.lock.json across a solution, and this bug causes extra files to match. eg. the Azure Pipelines cache task considers this a 'cache miss' as the extra packages.lock.json files are noticed after the build has completed.

Steps To Reproduce

  1. dotnet new web
  2. dotnet build /p:RestorePackagesWithLockFile=True

Note that packages.lock.json is now present in the bin/Debug/net8.0 output directory

Exceptions (if any)

No response

.NET Version

8.0.202

Anything else?

No response

flcdrg commented 4 months ago

A temporary workaround is to add this to the .csproj file:

<Content Remove="packages.lock.json" />
wtgodbe commented 4 months ago

@javiercn is this something that StaticWebAssets controls, or should we ping Vijay?

mkArtakMSFT commented 4 months ago

Ping @javiercn

javiercn commented 3 months ago

@mkArtakMSFT @wtgodbe this isn't us, as the packages.lock.json is not inside the wwwroot folder.

@vijayrkn any thoughts?

javiercn commented 3 months ago

The fix is likely https://github.com/dotnet/sdk/blob/f6c64dcc881dbda28db6747d83ab061c8713582d/src/StaticWebAssetsSdk/Sdk/Sdk.StaticWebAssets.StaticAssets.ProjectSystem.props#L4 (This is shared between the Web SDK and us because of layering)

mkArtakMSFT commented 3 months ago

@javiercn do you mean this is already fixed by a change that you've done?