ASP.NET process is spawned with confusing working directory #83

Closed
opened 2026-01-29 16:30:14 +00:00 by claunia · 5 comments
Owner

Originally created by @tboby on GitHub (Dec 6, 2017).

Originally assigned to: @robertmuehsig, @GregorBiswanger on GitHub.

When Electron.NET starts the asp.net application process it doesn't set a cwd. This means the cwd of the running process is used. Confusingly this is the location of electron.cmd, which is app\node_modules\.bin\.

Would it not make more sense for the asp.net application to start with its own directory as the cwd? This means calls such as File.ReadAllLines("./appsettings.json") behave as expected.

Currently that would read app\node_modules\.bin\appsettings.json not app\bin\appsettings.json.

200f511940/ElectronNET.Host/main.js (L51-L52)

I think the change would be something like:

var options = { cwd: path.join(__dirname,'bin') }
apiProcess = process(binFilePath, parameters, options);
Originally created by @tboby on GitHub (Dec 6, 2017). Originally assigned to: @robertmuehsig, @GregorBiswanger on GitHub. When Electron.NET starts the asp.net application process it doesn't set a cwd. This means the cwd of the running process is used. Confusingly this is the location of `electron.cmd`, which is `app\node_modules\.bin\`. Would it not make more sense for the asp.net application to start with its own directory as the cwd? This means calls such as `File.ReadAllLines("./appsettings.json")` behave as expected. Currently that would read `app\node_modules\.bin\appsettings.json` not `app\bin\appsettings.json`. https://github.com/ElectronNET/Electron.NET/blob/200f51194062a953e1924c309e4de65941f2119b/ElectronNET.Host/main.js#L51-L52 I think the change would be something like: ``` var options = { cwd: path.join(__dirname,'bin') } apiProcess = process(binFilePath, parameters, options); ```
claunia added the bugenhancement labels 2026-01-29 16:30:14 +00:00
Author
Owner

@robertmuehsig commented on GitHub (Dec 6, 2017):

Mh - I'm not sure what the working directory really is, but at least appSettings should work fine, see this https://github.com/ElectronNET/Electron.NET/issues/42 with this sample commit 24ef987471 (diff-627e2365a214cf35b5d1d98ef9b1a9c5)

@robertmuehsig commented on GitHub (Dec 6, 2017): Mh - I'm not sure what the working directory really is, but at least appSettings should work fine, see this https://github.com/ElectronNET/Electron.NET/issues/42 with this sample commit https://github.com/ElectronNET/Electron.NET/commit/24ef9874716cb5546e65fabf12c5ffb05533bd3f#diff-627e2365a214cf35b5d1d98ef9b1a9c5
Author
Owner

@robertmuehsig commented on GitHub (Dec 6, 2017):

But maybe it would be good anyway to set the working directory properly - good catch!

@robertmuehsig commented on GitHub (Dec 6, 2017): But maybe it would be good anyway to set the working directory properly - good catch!
Author
Owner

@jcphlux commented on GitHub (Dec 12, 2017):

I am using env.ContentRootPath and env.WebRootPath that might get you the path you need.

@jcphlux commented on GitHub (Dec 12, 2017): I am using env.ContentRootPath and env.WebRootPath that might get you the path you need.
Author
Owner

@robertmuehsig commented on GitHub (Feb 19, 2018):

It's quite late, sorry, but when did this occure? After you use "dotnet electronize build" or after "dotnet electronize start"?

@robertmuehsig commented on GitHub (Feb 19, 2018): It's quite late, sorry, but when did this occure? After you use "dotnet electronize build" or after "dotnet electronize start"?
Author
Owner

@tboby commented on GitHub (Feb 19, 2018):

I thought after both, the javascript that starts the backend is the same I think.
I fixed it by manually setting the CWD in the app, but that's not ideal!

@tboby commented on GitHub (Feb 19, 2018): I thought after both, the javascript that starts the backend is the same I think. I fixed it by manually setting the CWD in the app, but that's not ideal!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#83