gpt4 book ai didi

asp.net-core - 部署时未提供 Nuget 包内容文件

转载 作者:行者123 更新时间:2023-12-05 03:56:47 28 4
gpt4 key购买 nike

我已经构建了 NuGet package由 .net core 2.2 的 Razor 类库 (RCL) 项目组成。打包后,我看到它包含我配置的静态 Assets :

package details - sample asset

当我在目标项目中安装包时, Assets 引用在项目结构中可见: enter image description here

但是当我尝试在运行时访问它们时 - 我得到 404: https://localhost:44312/localizer-assets/lib/vue/vue.min.js

我看到这些文件并没有“物理地”放在 wwwroot 文件夹中(它们在内部包文件夹中)。

有什么方法可以提供这些文件吗?这应该如何配置?

到目前为止,我一直在使用这些方法:

https://www.learnrazorpages.com/advanced/razor-class-library

Can Razor Class Library pack static files (js, css etc) too?

当我直接引用 RCL 项目时它们工作正常,但当与 NuGet 一起打包并安装时它们不再工作。

最佳答案

They work fine when I directly reference RCL project, but when packed with NuGet and installed does not work any more.

据我所知,当你使用 nuget 并选择 PackageReference nuget management foramt ,目标导入到主工程中的文件以链接的形式引入到你的主工程中(对应的文件不会存在于你的解决方案的物理路径中,但会链接到对应的文件地址在 %userprofile%\.nuget\xxx 中)。这是PackageReference nuget管理格式的特性。

解决方案

要解决它,我认为您可以在 nuget 项目中添加自定义构建目标 (Include MSBuild props and targets in a package)。使用它,您可以将文件从 nuget 包复制到主项目中。

1.在\build文件夹(必须创建在项目根目录)。这些都是基于nuget的打包机制。

2.将这些代码添加到目标文件中

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<SourceScriptFiles Include="$(MSBuildThisFileDirectory)..\content\xxxx(relative paths in the current project)" />
</ItemGroup>
<Target Name="CopyScriptsToProject" BeforeTargets="Build">
<Copy SourceFiles="@(SourceScriptFiles)" DestinationFolder="$(ProjectDir)\wwwroot\xxxx\"
/>
</Target>
</Project>

使用目标将文件@(SourceScriptFiles)复制到主项目中。(DestinationFolder只是目标地址)。

3.如果你使用 nuspec 文件来打包你的包。您还应该将这些文件添加到其中的 files 节点下。

<files>
<!-- Include everything in \build -->
<file src="build\**" target="build" />

<!-- Other files -->
<!-- ... -->
</files>

另外,这样的操作是一个pre-build事件,当你安装包时,你应该先构建你的项目,然后你会在目标文件夹。

此外,这里是a good sample in the github希望能给出详细的资料和步骤。希望对您有所帮助。

关于asp.net-core - 部署时未提供 Nuget 包内容文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59066458/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com