如何使用 nuget 包资源管理器创建具有发布和调试 dll 的 nuget 包? [英] How to create a nuget package with both release and debug dll's using nuget package explorer?

查看:19
本文介绍了如何使用 nuget 包资源管理器创建具有发布和调试 dll 的 nuget 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Nuget 包资源管理器来创建一些 nuget 包.我设法做到了,只是在 VS 中以 Release 模式构建了一个项目,并将 dll 和 pdb 文件添加到包中.

I'm using the Nuget Package Explorer to create some nuget packages. I've managed to do so just building a project in Release mode in VS and adding both the dll and pdb files to the package.

到目前为止一切都很好,但是当我将包添加到另一个项目并尝试在调试时单步执行代码时,它会跳过它.

So far so good, but when I add the package to another project and try to step into the code while debugging, it will step over it instead.

我知道如果我想在调试时进入代码,我需要构建并添加调试 dll 和 pdb 到我的包中.我不确定如何将这些添加到我已经创建的包中,该包已经包含名称相同的 Release dll 和 pdb 文件.

I understand that I need to build and add the Debug dll and pdb to my package if I want to step into the code while debugging. I'm not sure though how to add these to the package I've already create, which already contains the Release dll and pdb file, which are named the same.

有什么想法吗?

推荐答案

我的想法是,NuGet 打包与约定有关.

My thoughts are, NuGet packaging is a lot about conventions.

不同平台打包相同的命名空间和相同的名称没有问题(如lib/net40/mydll.dlllib/net35/mydll.dll 等),因为 NuGet 将按平台过滤注册的依赖项.

There is no problem in packaging same namespaces and same names for different platforms (as in lib/net40/mydll.dll, lib/net35/mydll.dll etc in the same package), as NuGet will filter registered dependencies by platform.

为同一平台构建多个版本似乎非常规这个讨论 偏向于为每个构建制作一个包.这并不意味着你不能这样做,但你应该先问问自己是否应该这样做.

Building several versions for the same platform seems unconventional, this discussion is biased towards making a package per build. That doesn't mean you can't do it, but you should first ask yourself if you should.

也就是说,如果您的调试和发布版本非常不同(条件编译等),这可能很有用.但是,最终用户在安装您的软件包时将如何选择发布或调试?

That said, if your debug and release builds are very different (conditional compiling etc) this might useful though. But how will end-users choose Release or Debug when installing your package?

一个想法可能是,每个构建配置一个版本.两者都可以安装进入项目.为此,请添加 将文件定位到您的包 或构建 一个 powershell 安装脚本(不支持,因为 Nuget v3) 直接在目标项目文件中添加条件引用,如果你想要一些比 MsBuild 可以做的更简单的东西给你.

An idea could be, one version per build configuration. Both can be installed into the project. To do that, either add a targets file to your package or build a powershell install script (unsupported since Nuget v3) that adds conditional references directly in the target project file, if you want something less basic than whatever MsBuild can do for you.

第一种策略的示例:创建一个 .target 文件(在您的包中,创建一个 build 文件夹,然后创建具有以下内容的 buildYourLib.targets):

Example of the first tactic: Create a .target file (in your package, create a build folder and then create buildYourLib.targets with the following contents):

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
    <Reference Include="YourLib">
      <HintPath>..packagesYourLib.1.0.0libDebugYourLib.dll</HintPath>
    </Reference>
  </ItemGroup>

  <ItemGroup Condition="'$(Configuration)' == 'Release'">
    <Reference Include="YourLib">
      <HintPath>..packagesYourLib.1.0.0libReleaseYourLib.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>

如果您创建了 debug 和 release 文件夹(平台文件夹是可选的),构建输出将根据配置有效地改变 - 假设数据包消费者具有常规配置名称,但您始终可以扩展条件逻辑使用 $(Configuration).Contains etc 或将其放入包自述

Providing you created debug and release folders (platform folder is optional), the build output will effectively change depending on configuration - provided packet consumers have conventional configuration names, but you could always extend the condition logic a bit with $(Configuration).Contains etc or just put that in the package readme

这篇关于如何使用 nuget 包资源管理器创建具有发布和调试 dll 的 nuget 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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