So far, I have managed to create a Windows service, and then I can get TeamCity to build and compose and make available for Octopus Deploy.
What I cannot do is have app.config, which has a connection string in it and uses this connection string.
Below is my Deploy.ps1:
# 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 }
Here is my .nuspec file:
<?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>
If I try to access ConfigurationManager.ConnectionStrings ["MyConnectionString"], I will get a null reference.
Any suggestions?
source share