使用云config(ServiceDefinition.csdef)文件的配置创建Nuget Pacakge [英] Create Nuget Pacakge with configuration of cloud config(ServiceDefinition.csdef) file

查看:45
本文介绍了使用云config(ServiceDefinition.csdef)文件的配置创建Nuget Pacakge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的附加组件构建Nuget软件包,最终用户将使用该软件包来作为启动任务进行安装,然后他们将其应用程序上载到window azure平台上.

I would like to build Nuget package for my add-on which will be used by end user to install as startup task and after that they will upload their applications on window azure platform.

让我们以一个简单的Web应用程序为例,现在一个使用Nuget最终用户的云项目将添加附加软件包,它将在Web应用程序项目&中添加2个文件(exe& config).如图所示,将启动任务添加到云项目的ServiceDefinition.csdef中

Let's take one simple web application and one cloud project now using Nuget end user will added add-on package it will add 2 files(exe & config) in web application project & add startup task to ServiceDefinition.csdef of cloud project as per shown in figure

如何创建这种类型的Nuget Pacakge?

How can i created this type of Nuget Pacakge?

谢谢.

更新:

我已经按照NICK的答案进行尝试,但是根据下图所示,我在云项目中遇到了2个webrole的问题.错误和错误,我按照下面的方法得到

I have tried according with NICK's answer however i am getting problem with 2 webrole in cloud project according to shown in below fig. and error i am getting as per below

我还有一个问题,如果我要通过命令行安装该Nuget软件包,那么我如何才能考虑所有webrole项目在解决方案中添加exe和配置文件?

Also i have one question that If i am installing that Nuget package with command line then how i can consider all webrole projects to add exe and config file in solution??

推荐答案

Nuget软件包基于以下约定工作: http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#From_a_convention_based_working_directory

Nuget packages work based on a convention: http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#From_a_convention_based_working_directory

对于exe和配置,您可以执行以下操作:

As far as the exe and config you can do the following:

  1. 在您的包目录中,创建以下目录
    • mkdir lib(用于exe)
    • mkdir内容(用于配置)

对于exe,您要做的就是将文件放在lib目录中,然后在元数据节点下修改.nuspec文件.应该有一个文件"节点(如果没有,则可以添加一个).在文件节点内添加以下内容:

All you have to do for the exe is drop the file in the lib directory and modify you .nuspec file just under the metadata node. There should be a "files" node (if not you can add one). Add something like this inside the files node:

<file src="content\my.exe" target="content\my.exe" />

配置略有不同.只需将一个名为myname.config.transform的文件添加到内容目录,然后将一个条目添加到.nuspec文件中:

The config is a little different. Just add a file named myname.config.transform to the content directory and add an entry into the .nuspec file:

需要注意的几件事:

  1. 如果您的应用程序中不存在配置文件,它将为您添加一个配置文件.
  2. 如果文件已经存在,则只需添加要转换的节点
  3. 转换文件将在您的节点上进行完全匹配,因此如果
  4. 中存在以下内容

您的配置文件:

<add key="test" value="myval"/>

在转换中,您有:

<add key="test" value="myval2"/>

结果文件如下:

<add key="test" value="myval"/>
<add key="test" value="myval2"/>

就添加启动任务而言,这对我来说有点棘手(可能会有更好的方法).我在install.ps1中使用了powershell(就像上面的文件一样,但是您为它创建了一个工具"目录):

As far as adding the startup task, that's been a little more tricky for me (there might be a much better way). I use powershell in the install.ps1 (just like the files above but you create a "tools" directory for it):

param($installPath, $toolsPath, $package, $project)

#Modify the service config - adding a new Startup task
$svcConfigFile = $DTE.Solution.Projects|Select-Object -Expand ProjectItems|Where-Object{$_.Name -eq 'ServiceDefinition.csdef'}
$ServiceDefinitionConfig = $svcConfigFile.Properties.Item("FullPath").Value
[xml] $xml = gc $ServiceDefinitionConfig

#Create startup and task nodes

# So that you dont get the blank ns in your node
$startupNode = $xml.CreateElement('Startup','http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition')
$taskNode = $xml.CreateElement('Task','http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition')
$taskNode.SetAttribute('commandLine','my.exe')
$taskNode.SetAttribute('executionContext','elevated')
$taskNode.SetAttribute('taskType','simple')
$startupNode.AppendChild($taskNode)

#Check to see if the startup node exists
$modified = $xml.ServiceDefinition.WebRole.StartUp
if($modified -eq $null){
    $modified = $xml.ServiceDefinition.WebRole
    $modified.PrependChild($startupNode)
}
else{
    $nodeExists = $false
    foreach ($i in $xml.ServiceDefinition.WebRole.Startup.Task){
        if ($i.commandLine -eq 'my.exe'){
            $nodeExists = $true
        }
    }
    if($taskNode -eq $null -and !$nodeExists){
        $modified.AppendChild($taskNode)
    }
}
$xml.Save($ServiceDefinitionConfig);

我希望这会有所帮助.

-尼克

这篇关于使用云config(ServiceDefinition.csdef)文件的配置创建Nuget Pacakge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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