Skip to content

Commit af4c2dd

Browse files
committed
Create and restore in separate steps
1 parent 463c4c3 commit af4c2dd

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/ProjectTemplates/Shared/Project.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ internal async Task RunDotNetNewAsync(
7070
// Used to set special options in MSBuild
7171
IDictionary<string, string> environmentVariables = null)
7272
{
73-
var hiveArg = $" --debug:disable-sdk-templates --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"";
73+
var hiveArg = $"--no-restore --debug:disable-sdk-templates --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"";
7474
var argString = $"new {templateName} {hiveArg}";
7575
environmentVariables ??= new Dictionary<string, string>();
7676
if (!string.IsNullOrEmpty(auth))
@@ -113,20 +113,27 @@ internal async Task RunDotNetNewAsync(
113113
Directory.Delete(TemplateOutputDir, recursive: true);
114114
}
115115

116-
using var execution = ProcessEx.Run(Output, AppContext.BaseDirectory, DotNetMuxer.MuxerPathOrDefault(), argString, environmentVariables);
117-
await execution.Exited;
116+
using var createExecution = ProcessEx.Run(Output, AppContext.BaseDirectory, DotNetMuxer.MuxerPathOrDefault(), argString, environmentVariables);
117+
await createExecution.Exited;
118118

119-
var result = new ProcessResult(execution);
119+
var createResult = new ProcessResult(createExecution);
120+
Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("restore", this, createResult));
121+
122+
argString = "restore /bl";
123+
using var restoreExecution = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), argString, environmentVariables);
124+
await restoreExecution.Exited;
125+
126+
var restoreResult = new ProcessResult(restoreExecution);
120127

121128
// Because dotnet new automatically restores but silently ignores restore errors, need to handle restore errors explicitly
122-
if (errorOnRestoreError && (execution.Output.Contains("Restore failed.") || execution.Error.Contains("Restore failed.")))
129+
if (errorOnRestoreError && (restoreExecution.Output.Contains("Restore failed.") || restoreExecution.Error.Contains("Restore failed.")))
123130
{
124-
result.ExitCode = -1;
131+
restoreResult.ExitCode = -1;
125132
}
126133

127-
CaptureBinLogOnFailure(execution);
134+
CaptureBinLogOnFailure(restoreExecution);
128135

129-
Assert.True(0 == result.ExitCode, ErrorMessages.GetFailedProcessMessage("create/restore", this, result));
136+
Assert.True(0 == restoreResult.ExitCode, ErrorMessages.GetFailedProcessMessage("restore", this, restoreResult));
130137
}
131138

132139
internal async Task RunDotNetPublishAsync(IDictionary<string, string> packageOptions = null, string additionalArgs = null, bool noRestore = true)

0 commit comments

Comments
 (0)