简体   繁体   English

我应该如何构建NuGet软件包?

[英]How am I supposed to be building NuGet packages?

I have a few functions I want to make available to many projects I'm working on. 我有一些功能想提供给我正在从事的许多项目。 So naturally I thought I should make a NuGet package to contain the shared code. 所以自然而然地,我想我应该制作一个NuGet包来包含共享代码。 so I: 所以我:

  1. Created a class library (in this case called ADUserCacheUsage). 创建了一个类库(在本例中为ADUserCacheUsage)。
  2. Fixed the Assembly Info for that class library. 修复了该类库的程序集信息。
  3. went to the directory with ADUserCacheUsage.csproj , and in a command window did nuget spec . 使用ADUserCacheUsage.csproj进入目录,并在命令窗口中执行nuget spec This generated a .nuspec file. 这将生成一个.nuspec文件。
  4. Fixed that nuspec file for my project. 修复了我的项目的nuspec文件。
  5. nuget pack ADUserCacheUsage.csproj -Build -Symbols -Properties Configuration=Release (after all, if someone externally is using the package, they only need the release build, right?) nuget pack ADUserCacheUsage.csproj -Build -Symbols -Properties Configuration=Release (毕竟,如果有人在外部使用该软件包,他们只需要发布版本,对吗?)
  6. nuget add ADUserCacheUsage.1.0.0.nupkg -source "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages"

So great, my NuGet package shows up when I select the machine source in the package manager. 太好了,当我在程序包管理器中选择机器源时,会显示我的NuGet程序包。 So I can use it in my projects. 所以我可以在项目中使用它。

I'm making a sample web page to use it. 我正在制作一个示例网页来使用它。 All the sample does is call one function and output the result on a web page. 该示例所做的只是调用一个函数并在网页上输出结果。

The problem is, whenever I try and run this sample project in debug mode, I get the warning message 问题是,每当我尝试在调试模式下运行此示例项目时,我都会收到警告消息

You are debugging a Release build of ADUserCacheUsage.dll. 您正在调试ADUserCacheUsage.dll的发布版本。

So presumably I should be including a debug version of my class library in my package, in addition to the release version, right? 因此,大概应该在发行版之外,在包中包括类库的调试版本,对吗? I wouldn't want the final release of the sample project to bother with the debugging information, potentially being slow and bloated (admittedly not much of an issue on a project that's just a sample, but I'm thinking for best practices and in the future where I might have a larger, more complex package). 我不希望示例项目的最终发行版会打扰调试信息,因为调试信息可能会很慢而且很blo肿(诚然,在一个仅作为示例的项目中,这个问题并不多,但是我正在考虑最佳实践,并且在将来我可能会有更大,更复杂的软件包)。

But I want to be able to run in debug without this error. 但我希望能够在调试中运行而不会出现此错误。 Whenever I make a web project, it includes many other projects, and it never gives me this error with regard to, for example, NewtonSoft.json . 每当我创建一个Web项目时,它都会包含许多其他项目,并且从不会给我有关NewtonSoft.json So what should I be doing in order to do this the right way? 那么,我应该怎么做才能正确地做到这一点? Does every package on nuget.org just include the debug version? nuget.org上的每个软件包是否都包含调试版本?

NuGet packages don't contain debug information. NuGet软件包不包含调试信息。

Instead, there are separate NuGet symbol packages (ending with .symbols.nupkg ) that contain debug symbols ( .pdb files) and the source code files. 而是有单独的NuGet符号包(以.symbols.nupkg结尾) ,其中包含调试符号( .pdb文件)和源代码文件。 Symbol packages can be created using either the nuget pack -Symbols or dotnet pack --include-symbols command tools. 可以使用nuget pack -Symbolsdotnet pack --include-symbols nuget pack -Symbols dotnet pack --include-symbols命令工具来创建符号包。

After the symbols packages are created and hosted (either on a symbol server or on the local file system), you can configure Visual Studio to use them to step through the code, even though the code in the NuGet package was built using Release mode. 创建并托管符号包之后(在符号服务器上或在本地文件系统上),即使NuGet包中的代码是使用Release模式构建的,也可以将Visual Studio配置为使用它们来单步执行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在开始一个新的 .Net Core 项目,但我不知道我应该如何为 nuget 包实现可为空的引用类型 - I am starting a new .Net Core project and I can't figure out how am I supposed to implement nullable reference types for nuget packages 我正在更新我的 nuget 包,但它们没有更新并不断出错 - I am updating my nuget packages and they are not updating and keep giving error 我该如何解决 NuGet 包的这个问题? - How can I solve this problem of NuGet packages? 如何隐藏依赖的 Nuget 包? - How can I hide dependent Nuget packages? 我应该如何避免这种代码? - How am I supposed to avoid this kind of code? 如何引用 NuGet 包? - How to reference NuGet packages? 如何在我的 iOS 和 Android 项目中用 .NET MAUI NuGet 包替换我的 Xamarin NuGet 包? - How can I replace my Xamarin NuGet packages with .NET MAUI NuGet packages in my iOS and Android projects? 如何列出所有已安装的 NuGet 包? - How do I list all installed NuGet packages? 如何在 VSCode 中为 nuget 包配置本地提要? - How can I configure a local feed for nuget packages in VSCode? 如何抑制nuget包中“垃圾”的产生? - How can I suppress the generation of 'trash' from nuget packages?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM