简体   繁体   English

如何在Visual Studio 2017社区中获取NuGet选项?

[英]How to get NuGet options in Visual Studio 2017 Community?

I am struggling with creating NuGet packages. 我正在努力创建NuGet软件包。 I am using Visual Studio 2017 Community edition. 我正在使用Visual Studio 2017社区版。

I have seen a couple of videos that show a "Pack" option on the menu when right-clicking the project in Solution Explorer. 我已经看过几个视频,这些视频在“解决方案资源管理器”中右键单击项目时在菜单上显示“打包”选项。 However, I do not have that option. 但是,我没有那个选择。 Is this one of the features in the other (non-Community) versions of Visual Studio? 这是Visual Studio其他(非社区)版本中的功能之一吗? I believe I have also seen a "create NuGet package on build" option mentioned somewhere. 我相信我也曾在某处提到过“在构建时创建NuGet软件包”选项。 I cannot find that either. 我也找不到。

I have tried various ways of using nuget, dotnet, and msbuild from the command line(s), but haven't had much success. 我已经尝试了从命令行使用nuget,dotnet和msbuild的各种方法,但是并没有取得太大的成功。 Very frustrating. 非常沮丧。

Any help is appreciated. 任何帮助表示赞赏。

If you really want to use Visual Studio, I would recommend installing an extension that helps you with that problem. 如果您真的想使用Visual Studio,我建议您安装一个扩展程序,以帮助您解决该问题。 For example, this one . 例如, 这个 The options people have in videos depend on the extensions they have installed. 人们在视频中拥有的选项取决于他们安装的扩展程序。 For you, it is the same. 对你来说,是一样的。

Alternatively, just use the command-line tooling for this as explained here or for .NET Core here or here . 或者,只需使用此处解释的命令行工具或此处此处的 .NET Core。

dotnet/msbuild pack is only available for SDK-style projects, but I believe works for all versions of Visual Studio, as well as on the command line. dotnet / msbuild包仅适用于SDK样式的项目,但我认为适用于所有版本的Visual Studio以及命令行。 .NET Core introduced these SDK-style projects, which can be identified by <Project Sdk="Microsoft.NET.Sdk"> . .NET Core引入了这些SDK样式的项目,可以通过<Project Sdk="Microsoft.NET.Sdk">进行标识。 If your project ( .csproj if it's a C# project) doesn't have the Sdk property or import Microsoft.NET.Sdk in either of the two other ways , then it's not an SDK style project and doesn't support packing in this way. 如果您的项目(如果为C#项目, Sdk .csproj )不具有Sdk属性或不通过其他两种方式导入Microsoft.NET.Sdk ,则它不是SDK样式的项目,因此不支持打包。 Another obvious difference between the two styles of projects is that SDK projects are only a few lines long from the new project template and don't list files in the project, whereas old style projects are typically a full screen long, even from a new project template with only a single class file, and it does list individual files in the project. 两种项目样式之间的另一个明显区别是,SDK项目距离新项目模板只有几行,并且不在项目中列出文件,而旧样式项目通常是全屏的,即使是新项目也是如此。模板只有一个类文件,并且确实列出了项目中的单个文件。 If you want to continue with this project type, you'll need to use nuget.exe pack and you'll probably want to create a .nuspec file to define some of the package metadata. 如果要继续使用此项目类型,则需要使用nuget.exe pack并且可能需要创建一个.nuspec文件来定义某些包元数据。

However, using SDK style projects is the future, it just takes time for all of Microsoft's existing project types to migrate. 但是,使用SDK样式的项目是未来,所有Microsoft现有项目类型的迁移都需要时间。 It's much simpler to use, so personally I would avoid old style projects unless you're using a project type (like ASP.NET, not ASP.NET Core) that doesn't support it. 它使用起来要简单得多,因此我个人会避免使用老式项目,除非您使用的项目类型(例如ASP.NET,而不是ASP.NET Core)不支持它。

All of this is confusing for anyone new to the .NET ecosystem. 所有这一切都使.NET生态系统新手感到困惑。 My recommendation is 1. when you install Visual Studio, when making your workload selections, make sure in the component list that .NET Core is selected, whatever the newest version of .NET Core that is available at the time of installation. 我的建议是1.安装Visual Studio时,在选择工作负载时,请确保在组件列表中选择了.NET Core,无论安装时是否有可用的.NET Core最新版本。 When creating a new project in Visual Studio, always select the .NET Core version, or .NET Standard version of any new project template, even if you want to target the (Windows) .NET Framework, in which case you edit the .csproj and change <TargetFramework>netstandard2.0</TargetFramework> to <TargetFramework>net45</TargetFramework> , although I would recommend multi-targeting possible by adding as to the element name and using a semi-colon separated list: <TargetFrameworks>net45;netstandard2.0</TargetFrameworks> . 在Visual Studio中创建新项目时,请始终选择任何新项目模板的.NET Core版本或.NET Standard版本,即使您要定位(Windows).NET Framework,在这种情况下,您也要编辑.csproj并将<TargetFramework>netstandard2.0</TargetFramework>更改为<TargetFramework>net45</TargetFramework> ,尽管我建议通过添加元素名称并使用分号分隔的列表来实现多目标: <TargetFrameworks>net45;netstandard2.0</TargetFrameworks> So, avoid the "Class Library (.NET Framework)" template, instead use "Class Library (.NET Standard)" and then change the target if you have to. 因此,请避免使用“类库(.NET Framework)”模板,而应使用“类库(.NET Standard)”,然后根据需要更改目标。

@zivkan led me down the right path. @zivkan带我走了正确的路。 Changing my project types to .Net Core from .Net Framework made all the options I mentioned in my original post available. 从.Net Framework将我的项目类型更改为.Net Core,使我在原始帖子中提到的所有选项都可用。 No extensions were needed. 无需扩展。

My .Net Core class library project now has the Pack and Publish options available on the project's context menu. 我的.Net Core类库项目现在在项目的上下文菜单上具有“打包”和“发布”选项。 In addition, there is a another tab (Package) on the project properties page. 此外,项目属性页面上还有另一个选项卡(包)。 On that page there is a "Generate NuGet package on build" option along with version, name, tags and other properties. 在该页面上,有一个“在生成时生成NuGet软件包”选项,以及版本,名称,标签和其他属性。

I have done much .Net framework development, but have been ignoring .Net Core and the newer options. 我已经做了很多.Net框架开发,但是一直忽略.Net Core和更新的选项。 I guess I need to dig in and learn about them. 我想我需要深入了解它们。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM