Nuget 包根据约定工作:
http ://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#From_a_convention_based_working_directory
至于 exe 和配置,您可以执行以下操作:
- 在您的包目录中创建以下目录
- mkdir lib(用于 exe)
- mkdir 内容(用于配置)
对于 exe,您所要做的就是将文件放到 lib 目录中,然后修改元数据节点下的 .nuspec 文件。应该有一个“文件”节点(如果没有,您可以添加一个)。在文件节点中添加类似这样的内容:
<file src="content\my.exe" target="content\my.exe" />
配置有点不同。只需将一个名为 myname.config.transform 的文件添加到内容目录,然后在 .nuspec 文件中添加一个条目:
有几点需要注意:
- 如果您的应用程序中不存在配置文件,它将为您添加一个。
- 如果已经存在文件,则只需添加要转换的节点
- 转换文件将在您的节点上进行完全匹配,因此如果以下内容存在于
你的配置文件:
<add key="test" value="myval"/>
在你的变换中,你有:
<add key="test" value="myval2"/>
生成的文件如下所示:
<add key="test" value="myval"/>
<add key="test" value="myval2"/>
至于添加启动任务,这对我来说有点棘手(可能有更好的方法)。我在 install.ps1 中使用了 powershell(就像上面的文件,但是你为它创建了一个“工具”目录):
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);
我希望这会有所帮助。
- 缺口