MSBuild不会将视图复制到输出文件夹 [英] MSBuild does not copy views to the output folder

查看:210
本文介绍了MSBuild不会将视图复制到输出文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到.NET Core 3.1之后,我的自制构建系统崩溃了。这是问题所在。我使用MSBuild在CI / CD管道中发布项目。这是我的代码:

After upgrading to .NET Core 3.1, my home-made build system broke. Here's the problem. I use MSBuild to publish a project in a CI/CD pipeline. This is my code:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe" C:\Company\Solution\Solution.sln /t:UserPanel /p:DeployOnBuild=true /p:PublishProfile=DeployUserPanel /p:SolutionDir=C:\Company\Solution /property:PublishFolder=C:\Publish\Solution\UserPanel /t:Publish

完全相同的代码会将 .cshtml 文件发布到.NET Core 2.2中的输出目录。但是现在我需要将它们从我的 UserPanel 项目手动复制/粘贴到publish文件夹中,这当然会破坏CI / CD的自动化。

The exact same code would publish .cshtml files to the output directory in .NET Core 2.2. But now I need to manually copy/paste them from my UserPanel project into the publish folder, which breaks the CI/CD automation of course.

我应该怎么解决?

推荐答案

.NET Core已移至对cshtml的预编译文件,因此在生产中不再需要它们。您将看到在发布输出中还应该有一个 [YourApp] .Views.dll ,其中包含已编译的视图。

.NET Core moved to pre-compiling the cshtml files so they are no longer needed in production. You will see that there should also be a [YourApp].Views.dll in the publish output which contains the compiled views.

如果您绝对需要旧的行为,请参考 ASP.NET Core中的Razor文件编译,以获取有关配置Razor运行时编译的文档。

If you absolutely need the old behavior, refer to Razor file compilation in ASP.NET Core for documentation on configuring Razor runtime compilation.

归结为将csproj更改为

It comes down to changing the csproj to

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <CopyRefAssembliesToPublishDirectory>true</CopyRefAssembliesToPublishDirectory>
    <CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
  </PropertyGroup>

并更改Startup.cs使其包含 .AddRazorRuntimeCompilation()来配置MVC:

And changing your Startup.cs to include .AddRazorRuntimeCompilation() on the call to configure MVC:

  public void ConfigureServices(IServiceCollection services)
  {
      services.AddControllersWithViews()
          .AddRazorRuntimeCompilation();
  }

这篇关于MSBuild不会将视图复制到输出文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆