Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 090a10b

Browse files
author
Ashish Jain (NUGET)
committed
Adding NuGet project lock file options for dotnet restore command
1 parent 3ccc359 commit 090a10b

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/dotnet/commands/dotnet-restore/LocalizableStrings.resx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,19 @@ This is equivalent to deleting project.assets.json.</value>
172172
<data name="CmdInteractiveRestoreOptionDescription" xml:space="preserve">
173173
<value>Allows the command to stop and wait for user input or action (for example to complete authentication).</value>
174174
</data>
175+
<data name="CmdLockedModeOptionDescription" xml:space="preserve">
176+
<value>Do not allow updating project lock file.</value>
177+
</data>
178+
<data name="CmdLockFilePathOption" xml:space="preserve">
179+
<value>ProjectLockFile_Path</value>
180+
</data>
181+
<data name="CmdLockFilePathOptionDescription" xml:space="preserve">
182+
<value>Project lock file path to be used to write lock file.</value>
183+
</data>
184+
<data name="CmdReevaluateOptionDescription" xml:space="preserve">
185+
<value>Force restore to reevaluate all dependencies even if a lock file already exists.</value>
186+
</data>
187+
<data name="CmdUseLockFileOptionDescription" xml:space="preserve">
188+
<value>Enables project lock file to be generate/ used with restore.</value>
189+
</data>
175190
</root>

src/dotnet/commands/dotnet-restore/RestoreCommandParser.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,28 @@ private static Option[] FullRestoreOptions()
3131
"--interactive",
3232
LocalizableStrings.CmdInteractiveRestoreOptionDescription,
3333
Accept.NoArguments()
34-
.ForwardAs("-property:NuGetInteractive=true")) }).ToArray();
34+
.ForwardAs("-property:NuGetInteractive=true")),
35+
Create.Option(
36+
"--use-lock-file",
37+
LocalizableStrings.CmdUseLockFileOptionDescription,
38+
Accept.NoArguments()
39+
.ForwardAs("-property:RestorePackagesWithLockFile=true")),
40+
Create.Option(
41+
"--locked-mode",
42+
LocalizableStrings.CmdLockedModeOptionDescription,
43+
Accept.NoArguments()
44+
.ForwardAs("-property:RestoreLockedMode=true")),
45+
Create.Option(
46+
"--lock-file-path",
47+
LocalizableStrings.CmdLockFilePathOptionDescription,
48+
Accept.ExactlyOneArgument()
49+
.With(name: LocalizableStrings.CmdLockFilePathOption)
50+
.ForwardAsSingle(o => $"-property:NuGetLockFilePath={o.Arguments.Single()}")),
51+
Create.Option(
52+
"--reevaluate",
53+
LocalizableStrings.CmdReevaluateOptionDescription,
54+
Accept.NoArguments()
55+
.ForwardAs("-property:ReevaluateNuGetLockFile=true")) }).ToArray();
3556
}
3657

3758
public static Option[] AddImplicitRestoreOptions(

test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public class GivenDotnetRestoreInvocation
2929
[InlineData(new string[] { "--no-dependencies" }, "-property:RestoreRecursive=false")]
3030
[InlineData(new string[] { "-v", "minimal" }, @"-verbosity:minimal")]
3131
[InlineData(new string[] { "--verbosity", "minimal" }, @"-verbosity:minimal")]
32+
[InlineData(new string[] { "--use-lock-file" }, "-property:RestorePackagesWithLockFile=true")]
33+
[InlineData(new string[] { "--locked-mode" }, "-property:RestoreLockedMode=true")]
34+
[InlineData(new string[] { "--reevaluate" }, "-property:ReevaluateNuGetLockFile=true")]
35+
[InlineData(new string[] { "--lock-file-path", "<lockFilePath>" }, "-property:NuGetLockFilePath=<lockFilePath>")]
3236
public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs)
3337
{
3438
expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}");

0 commit comments

Comments
 (0)