将 JSON 文件从类库 nuget 包复制到 bin [英] Copy JSON file to bin from class library nuget package

查看:39
本文介绍了将 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="xxxappsettings.json" Pack="true" PackagePath="contentFilesanyany;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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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