简体   繁体   English

将Web服务部署到Nuget包

[英]Deploy Web Service to Nuget Package

I have several WCF and WebAPI services as well as MVC websites in a visual studio solution. 我在Visual Studio解决方案中有几个WCF和WebAPI服务以及MVC网站。 Currently, we are creating WebDeploy packages for these services and websites to deploy to IIS. 当前,我们正在为这些服务和网站创建WebDeploy包,以部署到IIS。 I'm starting to look into Octopus Deploy for deploying our services and websites instead of WebDeploy. 我开始研究Octopus Deploy而不是WebDeploy来部署我们的服务和网站。 However, Octopus Deploy uses Nuget packages to deploy. 但是,Octopus Deploy使用Nuget包进行部署。

I'm trying to figure out how I can easily create a Nuget package that contains all the files that would normally be published into a WebDeploy package. 我试图弄清楚如何轻松创建一个Nuget包,其中包含通常会发布到WebDeploy包中的所有文件。 This may not be all files in the project directory or the bin directory. 这可能不是项目目录或bin目录中的所有文件。 I found this blog post describing how to package a csproj into a Nuget package during the build, but I found that the resulting package didn't contain any of my dependency dll's. 我发现这篇博客文章描述了在构建过程中如何将csproj打包到Nuget包中,但是我发现生成的包不包含我的任何依赖dll。 I realize I could write a nuspec for each of these projects manually and include exactly the files I want, but I'm looking for a more automatic way as this would create more maintenance when my project changes. 我意识到我可以为每个项目手动编写一个nuspec并确切地包含我想要的文件,但是我正在寻找一种更自动的方式,因为当我的项目更改时,这会带来更多的维护。

Does anyone out there know a good way to generate a nuspec or Nuget package that contains only the files needed to run the application, similar to the way publishing to a WebDeploy package only includes the files it needs? 有没有人知道一种生成nuspec或Nuget软件包的好方法,该软件包仅包含运行该应用程序所需的文件,类似于发布到WebDeploy软件包中仅包含所需文件的方式?

Octopus Deploy has a CLI called "Octo.exe" that can package up your application into a NUPKG. Octopus Deploy有一个名为“ Octo.exe”的CLI,可以将您的应用程序打包为NUPKG。

You will need to install Octopus Tools which you can download from https://octopus.com/downloads 您将需要安装Octopus Tools,可以从https://octopus.com/downloads下载。

Please see http://docs.octopusdeploy.com/display/OD/Using+Octo.exe for the documentation and how to use it. 请参阅http://docs.octopusdeploy.com/display/OD/Using+Octo.exe以获取文档及其使用方法。

A good example to use Octo.exe is part of a Continuous Integration pipeline when the build has successfully passed you call it to package the application and send it to the Octopus server. 当成功通过构建时,使用Octo.exe的一个很好的示例是Continuous Integration管道的一部分,您可以调用它来打包应用程序并将其发送到Octopus服务器。

After some playing around with Visual Studio, MSBuild, and TeamCity, I discovered a method that works for me. 在对Visual Studio,MSBuild和TeamCity进行了一些尝试之后,我发现了一种对我有用的方法。 My issues was that I did not want to package up all the files in my project directory, only those that are necessary to run the application. 我的问题是我不想打包项目目录中的所有文件,而只打包运行应用程序所需的文件。 WebDeploy handles this quite nicely as one of the options when publishing. 作为发布时的一种选择,WebDeploy可以很好地处理此问题。 I already have settings in my csproj file that will create a WebDeploy package on build, but this is a zip file and I don't want the zip file in my Nuget package. 我的csproj文件中已经有设置,可以在构建时创建WebDeploy包,但这是一个zip文件,我不希望该zip文件位于我的Nuget包中。

I found 2 ways to deal with this: 我发现了两种解决方法:

  1. In TeamCity, I set up a new Build Configuration that will package any nuspec files I have and publish the resulting Nuget packages to my Octopus Deploy Nuget feed. 在TeamCity中,我设置了一个新的生成配置,该配置将打包我拥有的所有nuspec文件,并将生成的Nuget包发布到我的Octopus Deploy Nuget提要中。 I figured out that I can use the existing WebDeploy package that gets created by my CI build configuration as an artifact dependency and TeamCity can actually unpack the zip file when grabbing the artifacts as part of that dependency. 我发现我可以将由CI构建配置创建的现有WebDeploy软件包用作工件依赖项,并且在将工件作为该依赖项的一部分时,TeamCity实际上可以解压缩zip文件。 Then my nuspec file references the entire folder structure that was extracted from the zip file and packages it into a Nupak. 然后,我的nuspec文件引用了从zip文件中提取的整个文件夹结构,并将其打包到Nupak中。

  2. I was able to modify my csproj settings to use a specific publish profile I generated in Visual Studio that would perform a WebDeploy package to file system. 我能够修改csproj设置,以使用我在Visual Studio中生成的特定发布配置文件,该配置文件将执行WebDeploy包到文件系统。 This would result in the same folder structure as is in the zip file from #1, but simply copied to a directory. 这将导致文件夹结构与#1的zip文件中的文件夹结构相同,只是将其复制到目录中。 Then my Nuget build configuration could simply grab those dependencies and package them the same way as in #1. 然后,我的Nuget构建配置可以简单地获取那些依赖项,并将它们打包为与#1中相同的方式。

I decided to go with option #1 as it would require minimal changes to my existing csproj and CI build configuration, and it would not break our current method of deploying using WebDeploy. 我决定选择选项#1,因为它只需要对现有的csproj和CI构建配置进行最小的更改,并且不会破坏我们当前使用WebDeploy进行部署的方法。

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

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