dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.71k stars 1.06k forks source link

dotnet build not forwarding --using-lock-file switch to dotnet restore #10138

Open ganeshran opened 5 years ago

ganeshran commented 5 years ago

Steps to reproduce

dotnet build --use-lock-file

Expected behavior

The project builds with implict restore and passes the --use-lock-file switch to dotnet restore.

Actual behavior

Error Message: MSBUILD : error MSB1001: Unknown switch. Switch: --use-lock-file

Environment data

dotnet --info output: .NET Core SDK (reflecting any global.json): Version: 2.2.104 Commit: 73f036d4ac

Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.2.104\

Host (useful for support): Version: 2.2.2 Commit: a4fd7b2c84

.NET Core SDKs installed: 1.1.9 [C:\Program Files\dotnet\sdk] 2.1.104 [C:\Program Files\dotnet\sdk] 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.302 [C:\Program Files\dotnet\sdk] 2.1.402 [C:\Program Files\dotnet\sdk] 2.1.500 [C:\Program Files\dotnet\sdk] 2.1.502 [C:\Program Files\dotnet\sdk] 2.1.504 [C:\Program Files\dotnet\sdk] 2.2.102 [C:\Program Files\dotnet\sdk] 2.2.104 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

livarcocc commented 5 years ago

@nkolev92 @rrelyea should we be forwarding this additional parameter from commands that do implicit restore? Any other new parameters we should handle?

nkolev92 commented 5 years ago

There are 4 lock file related switches according to https://github.com/dotnet/cli/pull/9868.

I'm not sure all of them should be forwarded to the implicit restore. In particular --use-lock-file feels weird.

@anangaur Thoughts on this?

Maybe it's ok to forward all the options.

TiberiusDRAIG commented 2 years ago

Just want to bump this one due to the following scenario:

When building a .NET Core 3.1 project with the .NET 6 SDK, running dotnet restore followed by dotnet build --no-restore results in a build failure (apphost.exe missing). Allowing an implicit restore through dotnet build results in a successful build, but, since dotnet build doesn't accept the lock-file arguments, lock-files can't (as far as I can see) be used in this scenario. This causes problems when supporting previous releases in a CI environment where the latest SDK is installed on the build agents, which is pretty much exactly where we'd want to be using lock-files.

KalleOlaviNiemitalo commented 2 years ago

You can use dotnet build -restoreProperty:RestoreLockedMode=true instead of dotnet build --locked-mode, which doesn't work yet.

The -restoreProperty option is not shown in dotnet build --help but it is shown in dotnet msbuild --help. The RestoreLockedMode property is documented in Lock file extensibility - NuGet PackageReference in project files.

For --use-lock-file, you could likewise use -restoreProperty:RestorePackagesWithLockFile=true, but you don't need that if your projects have lock files already.

TiberiusDRAIG commented 2 years ago

@KalleOlaviNiemitalo Legend, thanks! I'll give that a try tomorrow.

alfechner commented 2 years ago

@KalleOlaviNiemitalo does this apply to other commands with implicit restore like for example dotnet pack, dotnet test and dotnet vstest as well?

KalleOlaviNiemitalo commented 2 years ago

@alfechner I don't know.