将 JSON 文件从类库 nuget 包复制到 bin

编程入门 行业动态 更新时间:2024-10-10 12:16:52
本文介绍了将 JSON 文件从类库 nuget 包复制到 bin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我为这个模糊的标题道歉,但我不知道如何措辞.

I apologize for the vague title, but I am not sure how to phrase it.

我正在使用自定义"appsettings.json 文件夹.json 文件位于使用它的类库中.我想创建一个 nuget 包来安装这个类库,但还要确保将 appsettings.json 复制到正确的目录中(如果我在控制台应用程序中安装它,则是构建输出目录).

I am working with a "custom" appsettings.json folder. The json file lives in the class library that is using it. I want to create a nuget package to install this class library but also make sure that appsettings.json is copied into the correct directory (if I am installing it in a console app, the build output directory).

我看到了一个答案"

如何我可以在我的 nuspec 文件中设置复制到输出目录"属性吗?

但我使用的是 VS 2019 和 .NET Standard 2.0.我很沮丧,因此感谢任何帮助(即使被告知不可能)!提前致谢.

but I am using VS 2019 and .NET Standard 2.0. I am pretty frustrated so any help (even if told not possible) is appreciated! Thanks in advance.

推荐答案

如果你只想在 net core 项目上安装这个 nuget 包,你可以在 net 标准项目的 csproj 文件下添加这些节点:

If you just want to install this nuget package only on net core projects, you could just add these node under the net standard project's csproj file:

<ItemGroup> <None Update="xxx\appsettings.json" Pack="true" PackagePath="contentFiles\any\any;content"> <PackageCopyToOutput>true</PackageCopyToOutput> </None> </ItemGroup>

然后,将net标准项目重新打包成nuget包,在新项目下安装之前,你应该首先清理 nuget 缓存.

Then, repack the net standard project into a nuget package, before install it under a new project, you should clean nuget caches first.

如果你想把这个nuget包安装到一个net framework项目中,你应该尝试使用net standard2.0 lib项目上的<package_id>.props文件.

If you want to install this nuget package into a net framework project, you should try to use <package_id>.props file on the net standard2.0 lib project.

请试试这个链接下的功能.

更多推荐

将 JSON 文件从类库 nuget 包复制到 bin

本文发布于:2023-11-14 14:20:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587444.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类库   文件   JSON   nuget   bin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!