Skip to content

SPA proxy stop script fails to run due to incorrect line endings #39261

@rpendleton

Description

@rpendleton

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When running an ASP.NET Core 6 project that uses SPA proxying, an error is logged to the console during startup:

info: Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager[0]
      No SPA development server running at https://localhost:44408 found.
'path/to/project/.../bin/Debug/net6.0/a447c16478b24b5c85fd2b88ca706735.sh: line 1: syntax error near unexpected token `{
'path/to/project/.../bin/Debug/net6.0/a447c16478b24b5c85fd2b88ca706735.sh: line 1: `function list_child_processes(){

From what I can tell, this is happening because the shell script that's generated by the SpaProxyLaunchManager uses CRLF line endings, whereas bash on macOS (and presumably any *nix OS?) only supports LF line endings. If I change the file to use LF line endings, I can manually run the script without encountering a syntax error.

Expected Behavior

I expect the SPA proxy stop script to run without encountering syntax issues. Presumably, this should be fixed by ensuring the generated shell script uses LF instead of CRLF line endings.

Steps To Reproduce

  1. Create an ASP.NET Core 6 with React.js project from a template
  2. Start the project
  3. Look at the output logged to the console during startup

I don't know if it's relevant, but I created the project in IntelliJ Rider. As far as I'm aware though, Rider is just directly using templates that are provided by dotnet.

Exceptions (if any)

No response

.NET Version

6.0.101

Anything else?

  • Microsoft.AspNetCore.SpaProxy 6.0.1
  • IDE: JetBrains Rider 2021.3.2
  • macOS 11.6.2

The code that generates this script was introduced by #35591 and can be found here:

private void LaunchStopScriptMacOS(int spaProcessId)
{
var fileName = Guid.NewGuid().ToString("N") + ".sh";
var scriptPath = Path.Combine(AppContext.BaseDirectory, fileName);
var stopScript = @$"function list_child_processes(){{
local ppid=$1;
local current_children=$(pgrep -P $ppid);
local local_child;
if [ $? -eq 0 ];
then
for current_child in $current_children
do
local_child=$current_child;
list_child_processes $local_child;
echo $local_child;
done;
else
return 0;
fi;
}}
ps {Environment.ProcessId};
while [ $? -eq 0 ];
do
sleep 1;
ps {Environment.ProcessId} > /dev/null;
done;
for child in $(list_child_processes {spaProcessId});
do
echo killing $child;
kill -s KILL $child;
done;
rm {scriptPath};
";
File.WriteAllText(scriptPath, stopScript);
var stopScriptInfo = new ProcessStartInfo("/bin/bash", scriptPath)
{
CreateNoWindow = true,
WorkingDirectory = Path.Combine(AppContext.BaseDirectory, _options.WorkingDirectory)
};

Metadata

Metadata

Assignees

Labels

area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.feature-spa

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions