Asp.net 如何使用app.config安装使用OctopusDeploy的Windows服务?
到目前为止,我已经能够创建一个Windows服务,然后我可以让TeamCity构建和打包,并为八达通部署提供服务 我似乎不能做的是,有一个app.config,其中有一个连接字符串,并使用该连接字符串 以下是my Deploy.ps1:Asp.net 如何使用app.config安装使用OctopusDeploy的Windows服务?,asp.net,windows-services,Asp.net,Windows Services,到目前为止,我已经能够创建一个Windows服务,然后我可以让TeamCity构建和打包,并为八达通部署提供服务 我似乎不能做的是,有一个app.config,其中有一个连接字符串,并使用该连接字符串 以下是my Deploy.ps1: # These variables should be set via the Octopus web portal: # # ServiceName - Name of the Windows service # # sc.exe is
# These variables should be set via the Octopus web portal:
#
# ServiceName - Name of the Windows service
#
# sc.exe is the Service Control utility in Windows
# Default the service name
if (! $ServiceName)
{
$ServiceName = "OctoService"
}
Write-Host "Service Name:" $ServiceName
# Get the exe name based ont the directory
$contentPath = (Join-Path $OctopusPackageDirectoryPath "content")
$configName = (Get-ChildItem $contentPath\*.config -Name | Select-Object -First 1)
$binPath = (Join-Path $OctopusPackageDirectoryPath "lib\net40")
$exeName = (Get-ChildItem $binPath\*.exe -Name | Select-Object -First 1)
$fullPath = (Join-Path $binPath $exeName)
Write-Host "Service Path:" $fullPath
Write-Host "Config Path:" (Join-Path $contentPath $configName)
Copy-Item (Join-Path $contentPath $configName) $binPath
$service = Get-Service $ServiceName -ErrorAction SilentlyContinue
if (! $service)
{
Write-Host "The service will be installed"
New-Service -Name $ServiceName -BinaryPathName $fullPath -StartupType Automatic
}
else
{
Stop-Service $ServiceName -Force
$fullPath = Resolve-Path $fullPath
& "sc.exe" config "$ServiceName" binPath= $fullPath start= auto | Write-Host
Start-Service $ServiceName
}
这是我的.nuspec文件:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<copyright>Copyright 2012</copyright>
</metadata>
<files>
<file src="app.config" target="content" />
<file src="Deploy.ps1" />
</files>
</package>
$id$
$version$
$title$
$author$
$author$
假的
$description$
版权所有2012
如果我尝试访问ConfigurationManager.ConnectionString[“MyConnectionString”],我将得到一个空引用
有什么建议吗?我的钱花在你身上,你需要将你的app.config命名为exename.exe.config,这样你的服务就会收到它
App.config是ide中使用的“临时”名称,它作为构建的一部分被重命名为任何exe名称我猜这是因为我没有使用OctoPack,所以在nuget目录(lib、content等)中包含文件的整个过程都是不对的。我会尝试一下,很快让你知道。宾果,就是这样。看起来使用Rename-Item cmdlet也可以让我自动执行此操作。下面是我为实现此功能而添加的新命令:重命名项(连接路径$binPath$configName)($exeName+“.config”)