将 Razor 库资源移动到 MVC 发布的文件夹

Move Razor library resources to MVC published folder

我有一个 Razor Class 库,在 Resources 文件夹中有一个 Razor 组件和一个 (Dutch/nl) 本地化资源 (.resx)。我在单独项目的 MVC 应用程序的视图上使用该组件,使用 <component> 标记。

当我 运行 我的 MVC 应用程序在 Visual Studio 中时,组件的本地化字符串得到正确检索。 但是,当我将 MVC 应用程序发布到 {publishfolder} 时,组件的 RazorComponentLibrary.resources.dll 文件最终位于 {publishfolder}\wwwroot\_framework\_bin\nl\ 文件夹中,并且无法检索本地化字符串。如果我手动 copy/move RazorComponentLibrary.resources.dll{publishfolder}\nl\ 文件夹一切正常。

是否可以在MVC应用的csproj中指定resource.dll不需要放在wwwroot文件夹,而是放在nl文件夹?

我已经尝试添加

<EmbeddedResource Include="full-path-to-resx-file" Link="Resources\RazorComponentLibrary.ComponentName.nl.resx" />

到 MVC 应用程序的 csproj,但这没有帮助。

好的,我找到了解决方案。我将以下任务添加到我的 MVC 应用程序的 csproj 文件中:

<Target Name="CopyRazorResourceFilesNl" AfterTargets="Publish">
    <Copy SourceFiles="$(PublishDir)\wwwroot\_framework\_bin\nl\RazorComponentLibrary.resources.dll" DestinationFolder="$(PublishDir)\nl" />
</Target>
<Target Name="CopyRazorResourceFilesEn" AfterTargets="Publish">
    <Copy SourceFiles="$(PublishDir)\wwwroot\_framework\_bin\en\RazorComponentLibrary.resources.dll" DestinationFolder="$(PublishDir)\en" />
</Target>

这会将 wwwroot 中的 dll 复制到 MVC 应用程序用于本地化的 nl(和 en)文件夹。我需要两个位置的 dll,所以这是完美的。

您可以在此处找到复制任务的参考资料:https://docs.microsoft.com/en-us/visualstudio/msbuild/copy-task?view=vs-2019