I’m using newest .Net 5 RC2. For some reason when I run debug, working directory is set to project directory, not “binDebugnet5.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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
Here is solution I found:
var Dir = Path.GetFullPath(AppContext.BaseDirectory + "../../../"); builder.AddRazorRuntimeCompilation(options => options.FileProviders.Add(new PhysicalFileProvider(Dir))); ;
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0