简体   繁体   English

如何从命令行更改 Kestrel 的内容根路径

[英]How to change of the content root path of Kestrel from command line

I am using Visual Studio to build my MVC website, in NET 6.0我正在使用 Visual Studio 在 NET 6.0 中构建我的 MVC 网站

When I publish I get an.exe which I can run it loads Kestrel, it outputs当我发布时,我得到一个可以运行的.exe,它加载 Kestrel,它输出

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: D:\GitHub\myProj\net.myProj.UiTests\bin\Debug\net6.0\uiBinariesForUiTests

I open a browser on localhost on port 5001 and all is good - the website works over localhost perfectly我在 localhost 上的 5001 端口上打开浏览器,一切都很好 - 该网站完美地在 localhost 上运行

I want to execute this file from within a test directory...我想从测试目录中执行这个文件......

I am using我在用

var fileName = outputPath + "\\net5.MyProj.Ui.exe";  
_iisProcess = new Process();
_iisProcess.StartInfo.Verb = "runas";
_iisProcess.StartInfo.FileName = fileName;
_iisProcess.EnableRaisingEvents = true;
_iisProcess.StartInfo.UseShellExecute = true;
_iisProcess.StartInfo.CreateNoWindow = false;
_iisProcess.Start();

The issue this causes is, it changes the content root path from这导致的问题是,它将内容根路径从

D:\GitHub\myProj\net.myProj.UiTests\bin\Debug\net6.0\uiBinariesForUiTests D:\GitHub\myProj\net.myProj.UiTests\bin\Debug\net6.0\uiBinariesForUiTests

to

D:\GitHub\myProj\net.myProj.UiTests\bin\Debug\net6.0 D:\GitHub\myProj\net.myProj.UiTests\bin\Debug\net6.0

When I execute the.exe, is there a way to explicitly state the content root path?当我执行.exe时,有没有办法明确 state 内容根路径?

Turns out, you need to set the directory原来,你需要设置目录

_iisProcess.StartInfo.WorkingDirectory = outputPath;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM