1

So this is something that I expected to be simple, but I am not sure what is going wrong.

I am working on a C#, ASP.NET Web API project, and I am trying to set a content path to some folder in the solution's root directory.

For some reason, no matter what I set the Working directory option to under Properties > Debug, printing out Directory.CurrentDirectory() in my applications startup logic is always the default (somewhere in the bin directory for that project). I tried using $(SolutionDir), but found that is not supported in C#. I then tried some relative paths and absolute paths but nothing is working.

Am I missing something here? Is this setting just not used for C# projects or does it have something to do with it being a ASP.NET project? I found other questions on here asking how to set the current directory, but the answers were to use exactly the setting I have been using.

I know I can technically just change where the build executable is located, but that seems like an ugly work-around when the logic of the application already uses the working directory.

EDIT: Some more details in response to some comments.

So the premise of this project is it is a C# Web API that serves as a backend for an angular app. The angular app is built separately into a zip file which is then stored in the resources of the C# program. Upon running, the files are extracted and served on localhost for client machines. When the program is run in debug mode, however, it just sets a root content path and serves the raw files for the angular frontend. My goal here is to remove some manual configuration in debug mode as to where the angular frontend is is on disk. It is checked into the root of the solution directory, so I am trying to set the current working directory for debugging to the solution directory, and then the program will just be able to work normally when being debugged from Visual Studio.

I hope that isn't confusing things further.

Ross Hays
  • 341
  • 4
  • 19
  • For asp.net applications, you should be using something like [Url.Content("~/Content/file.png"))](https://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.content%28v=vs.118%29.aspx?f=255&MSPPError=-2147217396) or [ResolveUrl("~/Content/file.png")](https://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveurl(v=vs.110).aspx) for non-MVC applications to get the path to the files in your content folder. Forget the working directory altogether for web apps. – itsme86 Nov 01 '16 at 22:15
  • @itsme86 Believe me when I say this is a bit of an unusual case. The debug mode of the application serves from a folder just to make life easier. When build in release mode it serves a copy of the web contents out of its own resources. This application is installed on another computer and just has a web frontend. Nothing hosted that I control. – Ross Hays Nov 01 '16 at 23:26
  • Maybe you can tell us what you aim to do? If you insist to set working directory for web application, you may check this post: [Creating virtual directories in IIS express](http://stackoverflow.com/questions/8735713/creating-virtual-directories-in-iis-express/8929315#8929315) if you using IIS express for debug – Prisoner Nov 02 '16 at 02:06
  • @Alex Added some more notes as an edit. Does that clear things up at all? – Ross Hays Nov 02 '16 at 02:12

0 Answers0