https://github.com/dotnet/cli/issues/7596
比如新建一个net core 1.1 mvc 项目,成功编译运行,然后正常发布成功。
发布目录为:E:\master\dotnet\WebApplication1\WebApplication1\bin\Release\PublishOutput
然后以下面两种方式运行
1: E:\> dotnet E:\master\dotnet\WebApplication1\WebApplication1\bin\Release\PublishOutput\WebApplication1.dll
2: E:\master\dotnet\WebApplication1\WebApplication1\bin\Release\PublishOutput\> dotnet WebApplication1.dll
第一个错误,直接错误为
“Error: The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'E:\appsettings.json'.”
env.ContentRootPath 等各种路径输出都是 ‘E:\’,尽管可以用某种方式把 env.ContentRootPath 这些路径手动修改正确,但是治标不治本,还会有新的路径错误,比如连 View 视图的路径都会错误
第二个正常
表现为:只要不在发布目录内运行,路径都会不对(路径输出为 dotnet 命令当下执行的目录),以各种可能的关键字搜索也一直没搜到相关的解决方案
解决思路:
1:从代码层面解决
2:从系统层面解决(Windows、Linux)
3:从 dotnet cli 层面解决