[英]Visual Studio publish ignores .js files in Views folder, for .NET Core
Here's the steps: 步骤如下:
If Views
folder is not in the published output, it's because your version of .NET Core compiles views by default. 如果
Views
文件夹不在发布的输出中,那是因为您的.NET Core版本默认情况下会编译视图。 Simply add this to your .csproj
: 只需将其添加到您的
.csproj
:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
</PropertyGroup>
And publish again. 并再次发布。
Home.js
file to Views/Default
folder Home.js
文件添加到Views/Default
文件夹 Home.cshtml
is published to the output folder, but Home.js
is not. Home.cshtml
被发布到输出文件夹,但Home.js
没有发布。 What's wrong here? 怎么了 This makes our deployment engine inefficient and we need to manually keep
.js
files in sync. 这使我们的部署引擎效率低下,我们需要手动保持
.js
文件同步。
Conventions are followed for a reason. 遵循约定是有原因的。 It promotes good app design.
它促进了良好的应用程序设计。 Having static files littered all over you project is not good app design .
在您的项目中到处乱堆的静态文件不是很好的应用程序设计 。 Still, you are correct that ASP.NET Core is configurable and can be made to do whatever you want to do with it, good or bad.
不过,您是正确的,因为ASP.NET Core是可配置的,并且可以使您执行它想做的任何事情,无论好坏。
You've actually got two issues here: 1) files in the Views
directory are not included in the publish and 2) the Views
directory is not served . 实际上,这里有两个问题:1)
Views
目录中的文件未包含在发布中; 2) Views
目录未提供 。 Even if you are successful including the static files in the publish, it's a pyrrhic victory, as you won't actually be able to utilize those files in your web pages. 即使您成功地将静态文件包含在发布中,这也是一个巨大的胜利,因为您实际上将无法在网页中使用这些文件。
There's no way that I'm aware of to cause an entire directory to be copied to output via the UI - only individual files. 我知道没有办法导致整个目录通过UI复制到输出-仅单个文件。 However, by editing your project file, you can add something like:
但是,通过编辑项目文件,您可以添加如下内容:
<ItemGroup>
<Content Include="Views\**\*.js" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
That then just leaves you with the issue of actually serving these files, which becomes more problematic, as you cannot just serve some files, but only entire directories. 这样一来,您实际上就无法处理这些文件,而问题就变得更加棘手,因为您不能只提供某些文件,而只能提供整个目录。 That means potentially exposing anything in the
Views
directory. 这意味着潜在地暴露
Views
目录中的任何内容。 Still, if you insist: 不过,如果您坚持:
app.UseStaticFiles(); // For the wwwroot folder
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "Views")),
RequestPath = "/Views"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.