Skip to content

Commit b3c6c43

Browse files
authored
Remove the need for a global lock when building or publishing a project (#21753)
* Change template test build and publish to not perform dotnet restore * Remove locking requirements for build and publish * Increase timeout for dotnet new operations since it's network bound
1 parent f87c1fc commit b3c6c43

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed

src/ProjectTemplates/Shared/AspNetProcess.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public AspNetProcess(
6363
Timeout = TimeSpan.FromMinutes(2)
6464
};
6565

66-
output.WriteLine("Running ASP.NET application...");
66+
output.WriteLine("Running ASP.NET Core application...");
6767

68-
var arguments = published ? $"exec {dllPath}" : "run";
68+
var arguments = published ? $"exec {dllPath}" : "run --no-build";
6969

7070
logger?.LogInformation($"AspNetProcess - process: {DotNetMuxer.MuxerPathOrDefault()} arguments: {arguments}");
7171

src/ProjectTemplates/Shared/ProcessLock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public ProcessLock(string name)
2424

2525
public async Task WaitAsync(TimeSpan? timeout = null)
2626
{
27-
timeout ??= TimeSpan.FromMinutes(2);
27+
timeout ??= TimeSpan.FromMinutes(20);
2828
Assert.True(await Semaphore.WaitAsync(timeout.Value), $"Unable to acquire process lock for process {Name}");
2929
}
3030

src/ProjectTemplates/Shared/Project.cs

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -109,48 +109,30 @@ internal async Task<ProcessResult> RunDotNetNewAsync(
109109
}
110110
}
111111

112-
internal async Task<ProcessResult> RunDotNetPublishAsync(bool takeNodeLock = false, IDictionary<string, string> packageOptions = null, string additionalArgs = null)
112+
internal async Task<ProcessResult> RunDotNetPublishAsync(IDictionary<string, string> packageOptions = null, string additionalArgs = null)
113113
{
114-
Output.WriteLine("Publishing ASP.NET application...");
114+
Output.WriteLine("Publishing ASP.NET Core application...");
115115

116-
// This is going to trigger a build, so we need to acquire the lock like in the other cases.
117-
// We want to take the node lock as some builds run NPM as part of the build and we want to make sure
118-
// it's run without interruptions.
119-
var effectiveLock = takeNodeLock ? new OrderedLock(NodeLock, DotNetNewLock) : new OrderedLock(nodeLock: null, DotNetNewLock);
120-
await effectiveLock.WaitAsync();
121-
try
122-
{
123-
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish -c Release /bl {additionalArgs}", packageOptions);
124-
await result.Exited;
125-
CaptureBinLogOnFailure(result);
126-
return new ProcessResult(result);
127-
}
128-
finally
129-
{
130-
effectiveLock.Release();
131-
}
116+
// Avoid restoring as part of build or publish. These projects should have already restored as part of running dotnet new. Explicitly disabling restore
117+
// should avoid any global contention and we can execute a build or publish in a lock-free way
118+
119+
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"publish --no-restore -c Release /bl {additionalArgs}", packageOptions);
120+
await result.Exited;
121+
CaptureBinLogOnFailure(result);
122+
return new ProcessResult(result);
132123
}
133124

134-
internal async Task<ProcessResult> RunDotNetBuildAsync(bool takeNodeLock = false, IDictionary<string, string> packageOptions = null, string additionalArgs = null)
125+
internal async Task<ProcessResult> RunDotNetBuildAsync(IDictionary<string, string> packageOptions = null, string additionalArgs = null)
135126
{
136-
Output.WriteLine("Building ASP.NET application...");
127+
Output.WriteLine("Building ASP.NET Core application...");
137128

138-
// This is going to trigger a build, so we need to acquire the lock like in the other cases.
139-
// We want to take the node lock as some builds run NPM as part of the build and we want to make sure
140-
// it's run without interruptions.
141-
var effectiveLock = takeNodeLock ? new OrderedLock(NodeLock, DotNetNewLock) : new OrderedLock(nodeLock: null, DotNetNewLock);
142-
await effectiveLock.WaitAsync();
143-
try
144-
{
145-
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build -c Debug /bl {additionalArgs}", packageOptions);
146-
await result.Exited;
147-
CaptureBinLogOnFailure(result);
148-
return new ProcessResult(result);
149-
}
150-
finally
151-
{
152-
effectiveLock.Release();
153-
}
129+
// Avoid restoring as part of build or publish. These projects should have already restored as part of running dotnet new. Explicitly disabling restore
130+
// should avoid any global contention and we can execute a build or publish in a lock-free way
131+
132+
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build --no-restore -c Debug /bl {additionalArgs}", packageOptions);
133+
await result.Exited;
134+
CaptureBinLogOnFailure(result);
135+
return new ProcessResult(result);
154136
}
155137

156138
internal AspNetProcess StartBuiltProjectAsync(bool hasListeningUri = true, ILogger logger = null)

0 commit comments

Comments
 (0)