Tuesday, November 8, 2016

Octopus update database by entityframework

Entity framework includes a tool called migrate.exe for use in deployment target to update database.
We can use that one in Octopus deployment. Here is the steps to get it working,

1. create a nuspec file in the project, make it the same name as the project name.
    make sure the id is the same package id as the Octopus package id
Add the below section in the file,
<files>
    <file src="..\packages\EntityFramework.6.1.3\tools\migrate.exe" target="tools"/>
    <file src="..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll" target="tools"/>
    <file src="..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.sqlserver.dll" target="tools"/>
    <file src="*.ps1" />
  </files>

2. Include the parameter OctoPackEnforceAddingFiles for uploading package
msbuild /t:build /p:RunOctoPack=true  /p:OctoPackEnforceAddingFiles=true .....

3. Create a new deployment step script

$installPath = $OctopusParameters['Octopus.Action[Deploy Package].Output.Package.InstallationDirectoryPath']
Write-Host "Installation Path:" $installPath

set-location "$($installPath)\tools"
Write-Host "Working Dir: "$(get-location)

.\migrate.exe <datamodel.dll> /StartUpDirectory="$($installPath)\bin" /StartUpConfigurationFile="$($installPath)\web.config"

Tuesday, November 1, 2016

Octopus msbuild cmd to publish the nuget package

Just record it here in case I will need it later,

msbuild /t:build /p:RunOctoPack=true /p:OctoPackPackageVersion=1.0.0-beta /p:OctoPackPublishPackageToHttp=http://<server>:3001/nuget/packages /p:OctoPackPublishApiKey=<apikey>

Also if the nuget is behind proxy, need to set it up with the command
  • nuget.exe config -set http_proxy=http://my.proxy.address:port
    nuget.exe config -set http_proxy.user=<domain>\<username>
    nuget.exe config -set http_proxy.password=<password>