Ensure dotnet run uses build output, not publish (#21720)
Fixes https://github.com/dotnet/aspnetcore/issues/17710
This commit is contained in:
parent
d99e7fecb0
commit
0e652d1aba
|
|
@ -44,7 +44,7 @@ namespace Templates.Test.Helpers
|
||||||
string workingDirectory,
|
string workingDirectory,
|
||||||
string dllPath,
|
string dllPath,
|
||||||
IDictionary<string, string> environmentVariables,
|
IDictionary<string, string> environmentVariables,
|
||||||
bool published = true,
|
bool published,
|
||||||
bool hasListeningUri = true,
|
bool hasListeningUri = true,
|
||||||
ILogger logger = null)
|
ILogger logger = null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -147,8 +147,33 @@ namespace Templates.Test.Helpers
|
||||||
["ASPNETCORE_Logging__Console__IncludeScopes"] = "true",
|
["ASPNETCORE_Logging__Console__IncludeScopes"] = "true",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var launchSettingsJson = Path.Combine(TemplateOutputDir, "Properties", "launchSettings.json");
|
||||||
|
if (File.Exists(launchSettingsJson))
|
||||||
|
{
|
||||||
|
// When executing "dotnet run", the launch urls specified in the app's launchSettings.json have higher precedence
|
||||||
|
// than ambient environment variables. When present, we have to edit this file to allow the application to pick random ports.
|
||||||
|
var original = File.ReadAllText(launchSettingsJson);
|
||||||
|
var updated = original.Replace(
|
||||||
|
"\"applicationUrl\": \"https://localhost:5001;http://localhost:5000\"",
|
||||||
|
$"\"applicationUrl\": \"{_urls}\"");
|
||||||
|
|
||||||
|
if (updated == original)
|
||||||
|
{
|
||||||
|
Output.WriteLine("applicationUrl is not specified in launchSettings.json");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Output.WriteLine("Updating applicationUrl in launchSettings.json");
|
||||||
|
File.WriteAllText(launchSettingsJson, updated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Output.WriteLine("No launchSettings.json found to update.");
|
||||||
|
}
|
||||||
|
|
||||||
var projectDll = Path.Combine(TemplateBuildDir, $"{ProjectName}.dll");
|
var projectDll = Path.Combine(TemplateBuildDir, $"{ProjectName}.dll");
|
||||||
return new AspNetProcess(Output, TemplateOutputDir, projectDll, environment, hasListeningUri: hasListeningUri, logger: logger);
|
return new AspNetProcess(Output, TemplateOutputDir, projectDll, environment, published: false, hasListeningUri: hasListeningUri, logger: logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal AspNetProcess StartPublishedProjectAsync(bool hasListeningUri = true)
|
internal AspNetProcess StartPublishedProjectAsync(bool hasListeningUri = true)
|
||||||
|
|
@ -163,7 +188,7 @@ namespace Templates.Test.Helpers
|
||||||
};
|
};
|
||||||
|
|
||||||
var projectDll = $"{ProjectName}.dll";
|
var projectDll = $"{ProjectName}.dll";
|
||||||
return new AspNetProcess(Output, TemplatePublishDir, projectDll, environment, hasListeningUri: hasListeningUri);
|
return new AspNetProcess(Output, TemplatePublishDir, projectDll, environment, published: true, hasListeningUri: hasListeningUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<ProcessResult> RunDotNetEfCreateMigrationAsync(string migrationName)
|
internal async Task<ProcessResult> RunDotNetEfCreateMigrationAsync(string migrationName)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue