Dživo Jelić
Dživo Jelić

Reputation: 2115

Asp.net Core env.ContentRootPath gives me Root Folder instead of Project folder

Both the env.ContentRootPath and Directory.GetCurrentDirectory() gives me path:

C:\\pathToProjects\\MyProjectRoot

But my Project is structured like this

├───.vscode
├───docs
├───src
│   └───MyProject
│       ├───project.csproj
├───test
│   └───MyProject.Tests
│       └───project.csproj
└───project.sln

Before migration and installation of 1.1.1 version i would get the folder that startup.cs files is in.

One more question if someone could help here. What is the difference between project.json files project.csproj files and which will be supported in the future and what about sln files how do we update those in vs code.

Upvotes: 1

Views: 6432

Answers (3)

Dživo Jelić
Dživo Jelić

Reputation: 2115

I was able to fix paths like this but i dont like it.

HACK:

var rootDirectory = Directory.GetCurrentDirectory() + "\\src\\MyProject";

if (hostingEnvironment.IsProduction())
{
    rootDirectory = hostingEnvironment.ContentRootPath;
}
hostingEnvironment.ContentRootPath = rootDirectory; //fix for path changes 

Upvotes: 0

lng
lng

Reputation: 805

See the cwd attribute in the launch.json file - it can be used to set the current working directory for finding dependencies and other files.

Debugging in VSCode

Upvotes: 4

Shayne Boyer
Shayne Boyer

Reputation: 410

There is an official comparison doc on the Microsoft docs site for the differences between project.json and csproj. See - https://learn.microsoft.com/en-us/dotnet/articles/core/tools/project-json-to-csproj

Upvotes: 1

Related Questions