diff --git a/src/ProjectTemplates/Shared/AspNetProcess.cs b/src/ProjectTemplates/Shared/AspNetProcess.cs index 1db1c00542..e5fa728290 100644 --- a/src/ProjectTemplates/Shared/AspNetProcess.cs +++ b/src/ProjectTemplates/Shared/AspNetProcess.cs @@ -63,9 +63,9 @@ namespace Templates.Test.Helpers Timeout = TimeSpan.FromMinutes(2) }; - output.WriteLine("Running ASP.NET application..."); + output.WriteLine("Running ASP.NET Core application..."); - var arguments = published ? $"exec {dllPath}" : "run"; + var arguments = published ? $"exec {dllPath}" : "run --no-build"; logger?.LogInformation($"AspNetProcess - process: {DotNetMuxer.MuxerPathOrDefault()} arguments: {arguments}"); diff --git a/src/ProjectTemplates/Shared/ProcessLock.cs b/src/ProjectTemplates/Shared/ProcessLock.cs index 44eb87e7fc..38c07a4768 100644 --- a/src/ProjectTemplates/Shared/ProcessLock.cs +++ b/src/ProjectTemplates/Shared/ProcessLock.cs @@ -24,7 +24,7 @@ namespace Templates.Test.Helpers public async Task WaitAsync(TimeSpan? timeout = null) { - timeout ??= TimeSpan.FromMinutes(2); + timeout ??= TimeSpan.FromMinutes(20); Assert.True(await Semaphore.WaitAsync(timeout.Value), $"Unable to acquire process lock for process {Name}"); } diff --git a/src/ProjectTemplates/Shared/Project.cs b/src/ProjectTemplates/Shared/Project.cs index 8ac3ef41f2..1fa0b57a26 100644 --- a/src/ProjectTemplates/Shared/Project.cs +++ b/src/ProjectTemplates/Shared/Project.cs @@ -109,48 +109,30 @@ namespace Templates.Test.Helpers } } - internal async Task RunDotNetPublishAsync(bool takeNodeLock = false, IDictionary packageOptions = null, string additionalArgs = null) + internal async Task RunDotNetPublishAsync(IDictionary packageOptions = null, string additionalArgs = null) { - Output.WriteLine("Publishing ASP.NET application..."); + Output.WriteLine("Publishing ASP.NET Core application..."); - // This is going to trigger a build, so we need to acquire the lock like in the other cases. - // We want to take the node lock as some builds run NPM as part of the build and we want to make sure - // it's run without interruptions. - var effectiveLock = takeNodeLock ? new OrderedLock(NodeLock, DotNetNewLock) : new OrderedLock(nodeLock: null, DotNetNewLock); - await effectiveLock.WaitAsync(); - try - { - using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish -c Release /bl {additionalArgs}", packageOptions); - await result.Exited; - CaptureBinLogOnFailure(result); - return new ProcessResult(result); - } - finally - { - effectiveLock.Release(); - } + // Avoid restoring as part of build or publish. These projects should have already restored as part of running dotnet new. Explicitly disabling restore + // should avoid any global contention and we can execute a build or publish in a lock-free way + + using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish --no-restore -c Release /bl {additionalArgs}", packageOptions); + await result.Exited; + CaptureBinLogOnFailure(result); + return new ProcessResult(result); } - internal async Task RunDotNetBuildAsync(bool takeNodeLock = false, IDictionary packageOptions = null, string additionalArgs = null) + internal async Task RunDotNetBuildAsync(IDictionary packageOptions = null, string additionalArgs = null) { - Output.WriteLine("Building ASP.NET application..."); + Output.WriteLine("Building ASP.NET Core application..."); - // This is going to trigger a build, so we need to acquire the lock like in the other cases. - // We want to take the node lock as some builds run NPM as part of the build and we want to make sure - // it's run without interruptions. - var effectiveLock = takeNodeLock ? new OrderedLock(NodeLock, DotNetNewLock) : new OrderedLock(nodeLock: null, DotNetNewLock); - await effectiveLock.WaitAsync(); - try - { - using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build -c Debug /bl {additionalArgs}", packageOptions); - await result.Exited; - CaptureBinLogOnFailure(result); - return new ProcessResult(result); - } - finally - { - effectiveLock.Release(); - } + // Avoid restoring as part of build or publish. These projects should have already restored as part of running dotnet new. Explicitly disabling restore + // should avoid any global contention and we can execute a build or publish in a lock-free way + + using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build --no-restore -c Debug /bl {additionalArgs}", packageOptions); + await result.Exited; + CaptureBinLogOnFailure(result); + return new ProcessResult(result); } internal AspNetProcess StartBuiltProjectAsync(bool hasListeningUri = true, ILogger logger = null)