0

I'm using newest .Net 5 RC2. For some reason when I run debug, working directory is set to project directory, not "bin\Debug\net5.0-windows". That causes some problems because I use some shared files from other projects (they are all copied into one folder on build) so it's important for me to have working dir in $(TargetDir). I tried to achieve it with 2 ways:

Change launchSettings.json like this:

  "profiles": {
    "WWW": {
      "commandName": "Project",
      "workingDirectory": "$(TargetDir)",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }
}

Change .csproj like this:

<PropertyGroup>
    <RunWorkingDirectory>$(MSBuildProjectDirectory)\bin\$(Configuration)\$(TargetFramework)\</RunWorkingDirectory>
</PropertyGroup>

both of these ways worked however RazorRuntimeCompilation is not working when I change working directory. Any suggestions?

2 Answers2

0

Since your working directory no longer contains the cshtml files, you need to mark them for copying to the ouput directory during the build in the csproj file:

<ItemGroup>
  <Content Update="**\*.cshtml" CopyToOutputDirectory="PreserveNewest" />
  <Content Update="**\*.razor" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

Do note that this means that you cannot apply live edits from within your IDE.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
0

Here is solution I found:

var Dir = Path.GetFullPath(AppContext.BaseDirectory + "../../../"); 
builder.AddRazorRuntimeCompilation(options => options.FileProviders.Add(new PhysicalFileProvider(Dir))); ;