使用 NuGet 添加对名为 *.Resources.dll 的文件的项目程序集引用

编程入门 行业动态 更新时间:2024-10-27 01:31:13
本文介绍了使用 NuGet 添加对名为 *.Resources.dll 的文件的项目程序集引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在确定包中的哪些 dll 应添加为程序集引用时,NuGet 会排除以.Resources.dll"结尾的任何内容.这旨在排除本地化的卫星程序集,但这意味着添加起来很棘手如果您有一个名为 MyCompany.Resources.dll 的 DLL,请提供参考.

NuGet excludes anything that ends ".Resources.dll" when determining which dlls in a package should be added as assembly references. This is designed to exclude the localised satellite assemblies, but it means it is tricky to add a reference if you have a DLL that is called MyCompany.Resources.dll.

有什么好的解决方法吗?

Are there any good workarounds for this?

推荐答案

我现在通过以下示例解决了这个问题 nuget.codeplex/workitem/1644,有一些修改.

I worked around this for now by following an example at nuget.codeplex/workitem/1644, with some modifications.

我添加了对网站项目的检查,因为它们不支持添加"方法.

I added a check for Website projects because they don't support the 'Add' method.

我在 nuspec 文件中的 metadata 元素之后添加了这个.(可能只有在您使用 NuGet 2.5 中可用的 includereferencedprojects 选项时才需要)

I added this after the metadata element in my nuspec file. (Probably only necessary if not you're using the includereferencedprojects option available in NuGet 2.5)

<files> <file src="bin\Release\Foo.Resources.dll" target="lib\net40" /> <file src="bin\Release\Foo.Resources.pdb" target="lib\net40" /> <file src="tools\*" target="tools" /> </files>

然后将这两个文件添加到我的项目目录中一个新的 tools 文件夹中.(请注意与 codeplex 示例相比,DLL 路径传递给 References.Add 方法的方式的修复)

And then added these two files to a new tools folders in my project directory. (Note the fix to the way DLL path is passed to the References.Add method, compared to the codeplex example)

Install.ps1

param($installPath, $toolsPath, $package, $project) $resourcesDll = Join-Path $installPath "lib\net40\Foo.Resources.dll" Write-Host "Adding resources DLL from " $resourcesDll if ($project.Kind -eq "{E24C65DC-7377-472b-9ABA-BC803B73C61A}") { $project.Object.References.AddFromFile($resourcesDll) } else { $project.Object.References.Add($resourcesDll) }

Uninstall.ps1

param($installPath, $toolsPath, $package, $project) Write-Host "Removing Foo.Resources reference" $project.Object.References | where { $_.Name -eq 'Foo.Resources' } | foreach { $_.Remove() }

更多推荐

使用 NuGet 添加对名为 *.Resources.dll 的文件的项目程序集引用

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

发布评论

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

>www.elefans.com

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