nuget.server包_为.NET引入NuGet软件包管理-Web堆栈的另一部分

nuget.server包

nuget.server包

NuGet

Microsoft's been filling out the Web Stack with more and more right-sized LEGO pieces lately, and today ScottGu announced the developer preview of NuGet. It's a piece of the stack that's been notably missing for years and after using it for a while now, I'm not sure how I lived without it.

微软最近一直在用越来越多的合适大小的乐高积木填充Web Stack,今天,ScottGu宣布了NuGet的开发人员预览版。 它是其中的一部分,已经丢失多年了,现在使用了一段时间后,我不确定没有它会怎样生活。

NuGet is a package management system for .NET. The goal of NuGet is to make the process of incorporating third party libraries into your solutions as simple as possible.

NuGet是.NET的软件包管理系统。 NuGet的目标是使将第三方库合并到您的解决方案中的过程尽可能地简单。

Package Management itself is not a new concept. From Apt and "deity" before it at the system-level on *nix, to Ruby Gems, Maven, Synaptic, portage, dpkg, rpm and others, it's a well understood space. There are package managers for operating systems that install machine-wide libraries, and there are package managers for developers and their projects that manage dependencies and install libraries. NuGet takes inspiration from Ruby Gems and adds some .NET specifics.

软件包管理本身并不是一个新概念。 从* nix上系统级的Apt和“神”到Ruby Gems,Maven,Synaptic,portage,dpkg,rpm等,这是一个广为人知的空间。 有用于安装机器范围库的操作系统的程序包管理器,也有用于管理依赖项和安装库的开发人员及其项目的程序包管理器。 NuGet从Ruby Gems汲取灵感,并添加了一些.NET细节。

NuGet-想法 (NuGet - The Idea)

Here's how it works. Notice the "Package Manager Console" window at the bottom of Visual Studio 2010. That's PowerShell. (It'll be in View | Other Windows for this release)

运作方式如下。 请注意Visual Studio 2010底部的“包管理器控制台”窗口。这是PowerShell。 (此版本将在View | Other Windows中)

I type List-Package and NuGet goes to a central ATOM feed and retrieves a list of packages like this (not complete, I snipped it for the example)

我输入List-Package,然后NuGet转到中央ATOM提要,并检索这样的软件包列表(不完整,在示例中我将其剪断了)

Id Version Description
-- ------- -----------
Antlr 3.1.1 ANother Tool for Language Rec...
Artem.XmlProviders 2.5 Implementation of XML ASP.NET...
AutoMapper 1.1.0.118 A convention-based object-obj...
Castle.Components.Validator 1.1.0 The Validator component is us...
Castle.Core 1.2.0 Core of the castle project
Castle.DynamicProxy 2.2.0 Castle DynamicProxy is a libr...
Castle.Ioc 2.1.1 Castle Project offers two Inv...
EFCTP4 1.0 This CTP is a an early previe...
elmah 1.1 ELMAH (Error Logging Modules ...
tarantino-db-deployer 1.0.146.0 This is a database migration ...
WebFormsMVP 0.9.7.2 A simple Model-View-Presenter...
xunit 1.6.1 xUnit.net is a developer test...

编号版本说明-------- ----------- Antlr 3.1.1另一种语言记录工具... Artem.XmlProviders 2.5 XML ASP.NET的实现... AutoMapper 1.1.0.118基于约定的对象-对象... Castle.Components.Validator 1.1.0 Validator组件是我们... Castle.Core 1.2.0城堡项目的核心Castle.DynamicProxy 2.2.0 Castle DynamicProxy是一个免费库。 Castle.Ioc 2.1.1 Castle Project提供两个Inv ... EFCTP4 1.0此CTP是早期的预览... elmah 1.1 ELMAH(错误记录模块... tarantino-db-deployer 1.0.146.0这是数据库迁移... WebFormsMVP 0.9.7.2一个简单的Model-View-Presenter ... xunit 1.6.1 xUnit.net是开发人员测试...

At this point, as an example, perhaps I want to get the ELMAH (Error Logging Modules and Handlers) open source library setup in my MVC project. I have long said that ELMAH, as a project, deserves way more attention than it gets.

在这一点上,作为示例,也许我想在我的MVC项目中获得ELMAH(错误记录模块和处理程序)开源库设置。 长期以来,我一直说,ELMAH作为一个项目,应该得到更多的关注

One of the reasons that it doesn't get used - as is the case with many .NET open source libraries - is that it takes too much effort to get it working. Unzip it, put it in a folder somewhere in your project, figure out what needs to be added to web.config, you know.

像许多.NET开源库一样,不使用它的原因之一是要花费太多的精力才能使其工作。 解压缩它,将其放在项目中的某个文件夹中,弄清楚需要添加到web.config中的内容。

With NuGet, I type "Install-Package elmah" and it's done. If I wanted to be extra cool with PowerShell aliases I could have just typed "install-packageelmah."

使用NuGet,我输入“ Install-Package elmah ”并完成。 如果我想对PowerShell别名更酷,可以输入“ install-packageelmah”

PM> Install-Package elmah
Successfully added 'elmah 1.1' to MvcApplication4

And that's it. Elmah is automatically brought down to my machine, a reference is added to my project and everything it needs is merged non-destructively into my web.config.

就是这样。 Elmah自动降到我的机器上,一个引用被添加到我的项目中,它所需要的一切都无损地合并到我的web.config中。

I'll run my app and hit /elmah.axd just to prove it.

我将运行我的应用程序并点击/elmah.axd来证明这一点。

复杂的软件包及其依赖性 (Complex Packages and their Dependencies)

Looks good. But what if I want to add a more complex project, maybe NHibernate.Linq. From the Package Manager Console I'll start typing install-package nh and get Intellisense for all the packages that are available.

看起来不错。 但是,如果我想添加一个更复杂的项目,也许是NHibernate.Linq。 从Package Manager控制台,我将开始输入install-package nh 并获取所有可用软件包的Intellisense。

And the console reports:

控制台报告:

PM> Install-Package NHibernate.Linq
'NHibernate.Core (>= 2.0)' not referenced. Retrieving dependency...Done 'log4net (= 1.2.1)' not referenced. Retrieving dependency...Done 'Iesi.Collections (= 1.0)' not referenced. Retrieving dependency...Done 'Antlr (>= 3.0)' not referenced. Retrieving dependency...Done Successfully added 'log4net 1.2.1' to MvcApplication4 Successfully added 'Iesi.Collections 1.0' to MvcApplication4 Successfully added 'Antlr 3.1.1' to MvcApplication4 Successfully added 'NHibernate.Core 2.1.2' to MvcApplication4 Successfully added 'NHibernate.Linq 1.0' to MvcApplication4

Notice that NHibernate.Linq knows its dependant on a bunch of other things. All those packages got pulled in and put in the packages folder. Notice the nupkg file there? That's just a ZIP file. Let's look inside.

注意,NHibernate.Linq知道其依赖于许多其他东西。 所有这些软件包都被拉入并放在packages文件夹中。 注意那里的nupkg文件吗? 那只是一个ZIP文件。 让我们看看里面。

Unzipping the nupkg we see lots of stuff. The binary is in there, but also a nuspec file that looks like this. Dig around in there and you'll find some standard packaging namespaces from openformats.org.

解压缩nupkg可以看到很多东西。 二进制文件在其中,但也有一个如下所示的nuspec文件。 在那儿挖掘,您会从openformats.org中找到一些标准的打包名称空间。


   
   
NHibernate.Linq 1.0 NHibernate Linq support is based on the existing, proven in production, Linq provider in NHibernate Contrib. The plans to overhaul that and merge that into NHibernate’s proper for the next release are still active, but the project team feels most strongly that production quality Linq support is something that we ought to provide for our users now. Ayende en-US false 2010-10-03T16:32:29 2010-10-03T16:32:29

NuGet walks its way up the dependency chain and gets all the packages it needs, installing each. Packages can add scripts, content, references, and even run postscripts (ahem) written in PowerShell if they need something fancy.

NuGet沿着依赖关系链前进,并获取所需的所有软件包,并安装每个软件包。 程序包可以添加脚本,内容,引用,甚至可以运行用PowerShell写成的Postscript(Ahem)(如果需要的话)。

I can even remove all that and its dependancies.

我什至可以删除所有这些内容及其相关性。

PM> Remove-Package NHibernate.Linq -RemoveDependencies

Let's add a few more interesting packages to my project. First, I'll add David Ebbo's wonderful T4MVC templates.

让我们向我的项目中添加更多有趣的包。 首先,我将添加David Ebbo出色的T4MVC模板。

PM> install-packageT4MVC
Successfully added 'T4MVC 2.6.30' to MvcApplication4

David's project isn't actually DLLs, it's a T4 template and a config file, but no problem, it's added to the project.

David的项目实际上不是DLL,它是T4模板和配置文件,但没问题,它已添加到项目中。

T4MVC in my project

Next I'll add the Entity Framework "Magic Unicorn" library that I love so much.

接下来,我将添加我非常喜欢的实体框架“ Magic Unicorn”库。

PM> install-packageEFCTP4

You are downloading EFCTP4 from Microsoft, the license agreement
to which is available at ....Check the package for additional dependencies,
which may come with their own license agreement(s).
Your use of the package and dependencies constitutes your acceptance
of their license agreements. If you do not accept the license agreement(s),
then delete the relevant components from your device.
Successfully added 'EFCTP4 1.0' to MvcApplication4

Note that this package includes some licensing stuff, as do many OSS projects, so I'm told as I get it. Finally I'll add SQL Compact Edition 4 as well with a little...

请注意,该软件包与许多OSS项目一样,都包含一些许可内容,因此我被告知。 最后,我还将添加一点SQL Compact Edition 4。

PM> install-packageSQLCE
Successfully added 'SQLCE 4.0.8402.1' to MvcApplication4

I've added NHibernate.Linq and four dependencies, then removed them all. I've added T4MVC, SQL Compact, Entity Framework CTP 4, and ELMAH.

我添加了NHibernate.Linq和四个依赖项,然后将其全部删除。 我添加了T4MVC,SQL Compact,Entity Framework CTP 4和ELMAH。

We see we can add basically anything to a solution and it's only modifying the solution, and the packages folder next to it. Nothing is being added to the GAC (Global Assembly Cache) and no one is installing anything or messing with things system-wide. NuGet is about affecting local projects and solutions...and possibly adding functionality to enable me to make changes even faster...

我们看到,我们基本上可以向解决方案中添加任何内容,而只需修改解决方案及其旁边的packages文件夹。 没有任何东西被添加到GAC(全局程序集缓存)中,也没有人在系统范围内安装任何东西或弄乱任何东西。 NuGet涉及到影响本地项目和解决方案...并可能添加功能以使我能够更快地进行更改...

你能说脚手架吗? (Can you say Scaffolding?)

I'll add one more interesting package. It's not a library like EFCTP4, or a database like SQLCE, or a T4 template like T4MVC. It's actually an example of PowerShell scripts that extend the Package Manager Console itself with new commands that interact with my project.

我将添加另一个有趣的包。 它不是像EFCTP4这样的库,也不是像SQLCE这样的数据库,也不是像T4MVC这样的T4模板。 它实际上是PowerShell脚本的一个示例,该脚本使用与我的项目交互的新命令扩展了Package Manager控制台本身。

Note: This is just a sample/example, because we want to see and hear what you want, and how you want to use it. Talk is cheap, show me the code! ;)

注意:这只是一个示例/示例,因为我们希望看到并听到您想要的内容以及您如何使用它。 谈话很便宜,请告诉我代码! ;)

Typing

打字

PM> install-packageMvcScaffold

adds new commands to my console via a PowerShell script. It adds Add-MvcView, so I could so something basic like

通过PowerShell脚本向我的控制台添加新命令。 它添加了Add-MvcView,所以我可以这样基本

PM> Add-MvcView Empty
Added file 'Views\Empty.aspx'

But that's not interesting. Let's assume I have a Code First class like this in my project and I've compiled once (in fact, a sample model is included with the EFCTP4 package):

但这并不有趣。 假设我的项目中有一个这样的Code First类,并且已经编译了一次(实际上,EFCTP4包中包含一个示例模型):

using System.Data.Entity;

namespace MvcApplication4.Models {
public class Product {
public int ID { get; set; }
public string Name { get; set; }
public double Price { get; set; }
}
public class MyProductContext : DbContext {
public DbSet Products { get; set; }
}
}

Since I've got a nice Product, why not:

既然我有一个不错的产品,为什么不呢?

PM> Scaffold-MvcViews -ModelType Product  Added file 'Views\Product\List.aspx'
Added file 'Views\Product\Details.aspx'
Added file 'Views\Product\Edit.aspx'
Added file 'Views\Product\Create.aspx'
Added file 'Views\Product\Delete.aspx'

Which gives me a nice scaffolded set of views generated from T4 Code Templates (or your custom ones, if you like)

这给了我从T4代码模板(或您喜欢的自定义视图)生成的一组不错的框架视图。

Pretty sweet. A lot has been done and prepped for me and all from the Package Manager Console within VS. I can personally see folks creating templates or meta-packages that encapsulate some CRUD (Create, Read, Update, Delete) best practices and sharing them via NuGet packages.

很甜在VS的Package Manager Console中,为我做了很多准备工作。 我可以亲眼看到人们创建的模板或元包封装了一些CRUD(创建,读取,更新,删除)最佳实践,并通过NuGet包进行共享。

可以危害用户界面吗? (Can Haz UI?)

I've focused on the Command Line, because it's awesome and "computers need to be hard©" but you could have certainly added your packages like this:

我专注于命令行,因为它很棒而且“计算机需要坚硬©”,但是您当然可以这样添加软件包:

Clicking Add Package Reference brings up this dialog box. Look familiar?

单击“添加软件包参考”将弹出此对话框。 看起来熟悉?

From here I can search for packages, install, as well as see what packages I've already got installed. I can also check for updates and download new versions.

在这里,我可以搜索软件包,进行安装,以及查看我已经安装了哪些软件包。 我还可以检查更新并下载新版本。

NuGet开发人员预览版 (NuGet Developer Preview)

Now this is just a Developer Preview, but look at it generically. We can interact with Visual Studio from PowerShell, package up Open Source libraries, scripts, content or perhaps even meta-packages (install-package hanselpack or install-package dearReaderLibs).

现在,这只是“开发人员预览”,但从总体上来看。 我们可以从PowerShell与Visual Studio进行交互,打包开放源代码库,脚本,内容,甚至是元包(安装包hanselpack或安装包dearReaderLibs)。

Phil talks about the Guiding Principles for NuGet on his blog. There will be a central feed with no central approval process for adding libraries. The community will police and moderate packages. But, anyone can host a feed. You can host an internal feed at your work, or even just point NuGet at a file system folder and share packages across your group.

菲尔在博客上谈论了NuGet指导原则。 将有一个中央供稿,没有用于添加库的中央批准程序。 社区将维持警惕并控制包裹。 但是,任何人都可以托管供稿。 您可以在工作中托管内部提要,甚至可以将NuGet指向文件系统文件夹并在您的组中共享软件包。

开源的 (Open Source)

NuGet is interesting for a couple of reasons. NuGet isn't a classic Microsoft closed-source project; it's been accepted into the CodePlex Outercurve Foundation and is entirely hosted and managed in a Mercurial Repository at the CodePlex.com Forge. Developers from inside Microsoft and developers from outside Microsoft have been committing to the same repository. All the bugs and issues are managed transparently on that projects.

NuGet之所以有趣,有几个原因。 NuGet不是经典的Microsoft封闭源项目; 它已被 CodePlex Outercurve基金会接受,并完全由CodePlex.com Forge的Mercurial存储库托管和管理。 Microsoft内部的开发人员和Microsoft外部的开发人员一直致力于同一存储库。 在该项目上透明地管理所有错误和问题。

Yeah, we're slow, but we're working to turn this ship around. NuGet can, and has, accepted contributions, most recently from some folks on the "Nu" open source project. In fact, working with the Nu folks caused us to change the name of this project from its original name of "NPack" to NuGet. There's been a lot of "Source Opened" at Microsoft and a lot of "Open Source but No Takebacks" with some Open Source, but with NuGet I'm stoked to see us start giving (and taking back) in a more open way.

是的,我们很慢,但是我们正在努力扭转这艘船。 NuGet可以并且已经接受了来自某些人最近在“ Nu”开源项目上所做的贡献。 实际上,与怒族人合作使我们将该项目的名称从其原始名称“ NPack”更改为NuGet。 微软有很多“开放源代码”的软件,还有很多开放源代码的“开源但没有收回”的软件,但是对于NuGet,我很高兴看到我们开始以更开放的方式进行捐赠(并收回)。

As Phil says, go over to the NuGet website on CodePlex and check out our guide to contributing to NuGet. It's early, and there's a LOT of work to be done, but we're planning to make this available for use in all editions of Visual Studio 2010.

正如Phil所言,请访问CodePlex上的NuGet网站,并查看我们为NuGet贡献的指南。 现在还很早,还有很多工作要做,但是我们正计划将其提供给所有版本的Visual Studio 2010。

立即使用ASP.NET MVC 3 Beta获取NuGet预览 (Get the NuGet Preview today with ASP.NET MVC 3 Beta)

Go get ASP.NET MVC 3 Beta and NuGet is included inside. Here's the direct download link.

去获取ASP.NET MVC 3 Beta ,其中包含NuGet。 这是直接下载链接

To summarize:

总结一下:

  • NuGet is open source and in the Outercurve Foundation

    NuGet是开源的,并且在Outercurve Foundation中
  • NuGet integrates with VS and with PowerShell

    NuGet与VS和PowerShell集成
  • NuGet will have a community managed gallery without central approving authority

    NuGet将拥有一个社区管理的画廊,而无需中央批准
  • NuGet won't mess up your computer or install anything outside your solution

    NuGet不会弄乱您的计算机或在解决方案之外安装任何东西
  • You can host your own feeds, or read packages out of a network share/folder

    您可以托管自己的提要,也可以从网络共享/文件夹中读取软件包

The whole team - inside and outside Microsoft - really hopes you like it.

微软内部和外部的整个团队真的希望您喜欢它。

除了个人:换工作 (Personal Aside: Changing Jobs)

An a related aside, one of the reasons I came to Microsoft was to work on and encourage open source like NuGet. For the last few years I've been working in MSDN and STO (Server and Tools Online) most recently leading a community team with a great bunch of folks, including Joe Stagner, Jon Galloway, Rey Bango, Jesse Liberty, and Pete Brown. This week I'm leaving MSDN to go to work as Community Architect for the Web Platform and Tools (WPT) team under ScottGu, Bill Staples and Omar Khan. Pete will take over as the lead of my team and they'll all join Developer Guidance (née Patterns and Practices). We'll hang out a lot together, though, I have no doubt, and I'll be at the Patterns and Practices Symposium as well as PDC 2010 this year.

除此之外,我来微软的原因之一就是致力于并鼓励像NuGet这样的开源。 在过去的几年中,我一直在MSDN和STO(服务器和工具在线)中工作,最近领导了一个由许多人组成的社区团队,其中包括Joe Stagner,Jon Galloway,Rey Bango,Jesse Liberty和Pete Brown。 本周,我要离开MSDN,去担任ScottGu,Bill Staples和Omar Khan领导的Web平台和工具(WPT)团队的社区架构师。 Pete将接任我的团队的领导,他们都将加入开发人员指南(née模式和实践)。 但是,毫无疑问,我们将一起聚会很多,并且我将参加今年的Patterns and Practices Symposium以及PDC 2010

The WPT team includes ASP.NET, IIS, as well as open source projects like NuGet, ASP.NET MVC and Orchard. I'll be promoting Open Source inside and outside Microsoft, making sure the customers voice is heard as products are architected, as well as speaking and teaching whenever they'll let me. I won't be moving to Seattle. ;)

WPT团队包括ASP.NET,IIS以及诸如NuGet,ASP.NET MVC和Orchard之类的开源项目。 我将在Microsoft内部和外部推广Open Source,以确保在设计产品时听到客户的声音,并在他们允许的时候进行演讲和教学。 我不会搬到西雅图。 ;)

翻译自: https://www.hanselman.com/blog/introducing-nuget-package-management-for-net-another-piece-of-the-web-stack

nuget.server包

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值