如何在Nuget包中包含resx文件

编程入门 行业动态 更新时间:2024-10-26 13:19:01
本文介绍了如何在Nuget包中包含resx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 Framework 4.6.1项目,可以从中制作一个nuget程序包.这个nuget软件包只需安装2个dll和几个内容文件,就可以正常工作.

I have a .Net Framework 4.6.1 project from which I make a nuget package. This nuget package simply installs 2 dlls and a couple of content files which is working fine.

问题是我现在通过驻留在以下位置的resx文件添加了资源字符串:

The problem is that I now added resource string via a resx file that resides in:

~\App_Data\Global\Resources\resource-strings.resx

我不知道如何使该文件正确地成为nuget包的一部分.创建.nupkg时,我会在那看到resx文件,但是当我将其安装在另一个项目中时,该resx文件应该复制到App_Data \ Global \ Resources文件夹中,但不是.

And I don't know how to make that file be part of the nuget package properly. When I create the .nupkg, I see the resx file there, but when I install it on another project, the resx file should be copied to the App_Data\Global\Resources folder, but it is not.

有可能吗?

根据我的调查,我认为我还必须对目标文件+ nuspec config进行一些操作,但是我没有尝试过.

From what I investigated, I think I also have to do something with the targets files + nuspec config, but nothing I have tried works.

我实际上只是需要将resx文件复制过来.没有比这更复杂的了.

I literally just need the resx file copied over. Nothing more complicated than that.

推荐答案

确定.这是可能的,可以通过nuget完成.由于您希望将此资源文件复制到目标asp net项目文件夹中,因此可以尝试以下步骤:

Sure. It is possible and can be done by nuget. Since you want this resource file be copied into your target asp net project folder, you could try the following steps:

======================================================

=====================================================

首先,如果要将此 net461 nuget软件包安装到 net框架 asp net项目中,则应使用 xxx.nusepc 中的"docs.microsoft/zh-cn/nuget/reference/nuspec#includes-content-files" rel ="nofollow noreferrer">内容节点>文件

First, if you want to install this net461 nuget package into a net framework asp net project, you should use content node in xxx.nusepc file

首先,请确保resource-strings.resx的 Build Action 是 Embedded Resource ,而不是 Content .

First, make sure that the Build Action of the resource-strings.resx is Embedded Resource rather than Content.

1) 首先,运行cmd命令: cd xxxx(项目文件夹路径),然后运行 nuget spec 生成nuspec文件.这些就足够了:

1) first, run cmd command :cd xxxx(project folder path) and then run nuget spec to generate the nuspec file. These are enough:

2)打开 nuspec 文件并添加内容节点:

2) open the nuspec file and add the content node:

<?xml version="1.0" encoding="utf-8"?> <package xmlns="schemas.microsoft/packaging/2010/07/nuspec.xsd"> <metadata> <id>xxx</id> <version>xxx</version> <title>xxx</title> <authors>xxx</authors> ............ </metadata> <files> <file src="~\App_Data\Global\Resources\resource-strings.resx(the path of the file in net framework 4.6.1 project)" target="content\App_Data\Global\Resources\resource-strings.resx" /> </files> </package>

3),然后保存 nuspec 文件并运行 nuget pack 以生成 nupkg .

3) then save the nuspec file and run nuget pack to generate the nupkg.

之前,安装nuget软件包之前,您应该首先清理nuget缓存,以删除旧的错误版本的nuget.

Before you install the nuget package, you should first clean nuget caches to remove the old wrong versions of the nuget.

安装此软件包时,该文件将被复制到Web项目的根路径 App_Data \ Global \ Resources \ resource-strings.resx .

When you install this package, the file will be copied into the root path App_Data\Global\Resources\resource-strings.resx of the web project.

=====================================================

====================================================

如果要将此软件包安装到新的sdk项目(Net Core或具有 PackageReference nuget管理格式的xxx)中,则应使用复制任务创建目标文件.

If you want to install this package into new sdk project(Net Core or xxx with PackageReference nuget management format), you could should create a target file with a copy task.

1).在net Framework 4.6.1项目中添加一个名为build的文件夹,然后添加一个名为< Package_id> .props 文件的文件.

1) add a folder called build in the net framework 4.6.1 project and then add a file called <Package_id>.props file.

注意,请确保nuget软件包的ID与< Package_id> .props 相同.从这里提示.

Note that you should make sure that the nuget package's id is the same as the <Package_id>.props. Hint from here.

2)将它们添加到< Package_id> .props :

<Project> <Target Name="CopyFilesToProject" BeforeTargets="Build"> <Message Text="Copy resource-strings.resx to project" /> <ItemGroup> <SourceScripts Include="$(MSBuildThisFileDirectory)..\content\**\*.*"/> </ItemGroup> <Copy SourceFiles="@(SourceScripts)" DestinationFiles="$(MSBuildProjectDirectory)\%(RecursiveDir)%(Filename)%(Extension)"/> </Target> </Project>

3)像这样修改 xxx.nuspec 文件:

<?xml version="1.0"?> <package > <metadata> <id>xxx</id> <version>xxx</version> <title>xxx</title> <authors>xxx</authors> <owners>me</owners> ............ </metadata> <files> <file src="~\App_Data\Global\Resources\resource-strings.resx" target="content\App_Data\Global\Resources\resource-strings.resx" /> <file src="build\xxx(like package_id).props" target="build"/> </files> </package>

4),则应使用 nuget pack 命令打包该项目.在安装此软件包之前,您应该先清理nuget缓存.

4) then you should use nuget pack command to pack this project. Before you install this package, you should first clean nuget caches first.

安装此nuget软件包后,应构建项目以运行此自定义复制目标,以将文件复制到主项目中.

After you install this nuget package, you should build your project to run this custom copy target to copy the file into your main project.

也,还有与此类似的问题.

更多推荐

如何在Nuget包中包含resx文件

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

发布评论

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

>www.elefans.com

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