简体   繁体   English

是否可以在调试期间在 Razor 类库中编辑 Razor 页面 (.cshtml) 而无需重新启动? VS 2017

[英]It's possible to editing Razor page (.cshtml) in Razor Class Library during debugging without restart? VS 2017

I have an ASP.Net MVC Core application that references the Razor class library that has SomePage.cshtml .我有一个ASP.Net MVC Core application ,它引用了具有SomePage.cshtmlRazor class library

When debugging the application, I can edit pages in the application ASP.Net MVC Core , and the changes are reflected in the browser (after refreshing).在调试应用程序时,我可以在应用程序ASP.Net MVC Core中编辑页面,并且更改会反映在浏览器中(刷新后)。

But when I edit pages in the Razor Class Library , the changes are not visible in the browser (after refreshing).但是当我在Razor Class Library中编辑页面时,更改在浏览器中不可见(刷新后)。 I need to stop the application and restart - then the changes will be visible in the browser.我需要停止应用程序并重新启动 - 然后更改将在浏览器中可见。

Is there any way to refresh edited pages in the Razor Class Library without restarting?有什么方法可以在不重新启动的情况下刷新 Razor 类库中的已编辑页面?

That's not possible. 那不可能 In .NET all class libraries must be compiled before executing the code and the compiled reference is included in the original project. 在.NET中,必须在执行代码之前编译所有类库,并且已编译的引用包含在原始项目中。 So any changes to the class libraries must be compiled again.so we need stop project to compile code and update refrence. 因此对类库的任何更改都必须重新编译。因此,我们需要停止项目来编译代码并更新引用。

It's possible after installing Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package.安装Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation包后可能。

Then configure:然后配置:

public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages();

    services.Configure<MvcRazorRuntimeCompilationOptions>(options =>
    {
        var libraryPath = Path.GetFullPath(
            Path.Combine(HostEnvironment.ContentRootPath, "..", "MyClassLib"));
        options.FileProviders.Add(new PhysicalFileProvider(libraryPath));
    });
}

More details here 更多细节在这里

You can edit .chtml files without stopping the solution. 您可以在不停止解决方案的情况下编辑.chtml文件。 just need to refresh the page after our correction. 只需在更正后刷新页面即可。 if you are using visual studio, c# code too can be edited by changing the settings. 如果您使用的是Visual Studio,则也可以通过更改设置来编辑c#代码。 press shift+f5 for hard refresh 按Shift + F5键进行硬刷新

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

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