How to stop build through dockerfile when unit test failed (Dockerfile + .NET Framework + Nunit Test + Docker Window Container - asp.net

I have to build stop when unit test fail through docker file. I am using .NET Framework (not Dot.Net Core). I have to write command either in power shell script or Docker file (if Unit test fail then build should be stop before execute next line of docker file.
.NET Framework 4.7.2
Docker Window container only
Unit test project (Nunit)
Asp.Net WebForms (old)
Nunit test runner
Steps,
I have create project for Unit test + WebForm + Class library.
I have created powershell script for run unit test project using Nunit test runner.
I have added path for script in docker file.
I have attached Docker file and power-shell script .
Docker file code here
`# escape=`
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-20200512-windowsservercore-ltsc2019
WORKDIR /src
COPY ./POC.Web/POC.Web.csproj ./POC.Web/
COPY ./POC.Entites/POC.Entites.csproj ./POC.Entites/
COPY ./POC.Business.Layer/POC.Business.Layer.csproj ./POC.Business.Layer/
COPY ./POC.UnitTests/POC.UnitTests.csproj ./POC.UnitTests/
COPY ./POC.UnitTests/packages.config ./POC.UnitTests/
COPY ./MttcPoc.sln .
RUN nuget restore MttcPoc.sln
COPY . .
RUN msbuild POC.UnitTests/POC.UnitTests.csproj /p:OutputPath=c:/out/tests
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
# testResult variable using in shellscript to get the result of unit test
ENV testResult="Passed"
RUN nuget install NUnit.Runners
COPY ./startuptest.ps1 /
RUN /startuptest.ps1
#RUN IF $testResult == "Passed" EXIT 0 ELSE EXIT -1
RUN if [ "$testResult" = "Passed" ] ; then true ; else false; fi
ENTRYPOINT ["powershell", "/startuptest.ps1"]
#*****************************************************
#Below line should not execute if unit test fail
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-20200512-windowsservercore-ltsc2019
ENV APP_ROOT=/inetpub/wwwroot `
CONNECTIONSTRINGS_CONFIG_MAP="" `
dockercomposeKey="From Docker file"
WORKDIR ${APP_ROOT}
RUN Import-Module WebAdministration; `
Set-ItemProperty -Path 'IIS:\AppPools\DefaultAppPool' -Name processModel.identityType -Value LocalSystem; `
New-WebApplication -Name 'app' -Site 'Default Web Site' -PhysicalPath $env:APP_ROOT
COPY ./startup.ps1 /
RUN /startup.ps1
#ENTRYPOINT ["powershell", "/startup.ps1"]
COPY --from=build c:/out/_PublishedWebsites/POC.Web ${APP_ROOT}
#************************************************************************`
Powershell script code here
$ProjectDir = "."
$OutDir = "$ProjectDir\testresults"
$testProjectPath = "c:\out\tests\POC.UnitTests.dll"
# Set nunit path test runner
$nunit_path = "$ProjectDir\NUnit.ConsoleRunner.3.11.1\tools\nunit3-console.exe"
# Run NUnit3 tests
& $nunit_path $testProjectPath --framework=net-4.7.2 --work=$OutDir
[XML]$resultDetails = Get-Content .\$OutDir\TestResult.xml
Write-Output $resultDetails
$string = "test-run"
Write-Output $resultDetails.$string.result
$env:testResult = $resultDetails.$string.result
#Passed
#Failed
#Below line added for if test fail then exit from docker build
If ($resultDetails.$string.result -eq 'Passed') {
Write-Output "Test passed"
Write-Output $env:testResult
return true
}else{
Write-Output "Test failed"
Write-Output $env:testResult
return -1
}

Related

Sonarscanner MSBuild tool is not running in pipeline - Jenkins

I am running this following pipeline which has stage "Build + Sonarscanner Analysis" for dotnetcore 2.2
The stage is set as follows
I have installed the tool in Global Configuration as suggested by
Sonarqube Documentation
Defined the tool in the environment as following
// Tools
MSBUILD_SQ_SCANNER_HOME = tool name: 'Scanner_for_MSBuild_4.7', type: 'hudson.plugins.sonar.MsBuildSQRunnerInstallation'
Pipeline Stage
stage ('Build + SonarQube analysis') {
agent {
docker {
image 'mcr.microsoft.com/dotnet/core/sdk:2.2'
}
}
steps {
dir ("app") {
withSonarQubeEnv('local') {
sh "dotnet ${MSBUILD_SQ_SCANNER_HOME}/SonarScanner.MSBuild.dll begin /k:\"Testing-Local\""
sh "dotnet build ${env.DotnetProjectName}"
sh "dotnet ${MSBUILD_SQ_SCANNER_HOME}/SonarScanner.MSBuild.dll end"
}
}
}
}
Result
I am getting the SonarScanner.MSBuild.dll is not executable as seen below
Verfication
The dll exists and the permissions is assigned to Jenkins
The dll is executable
The dll when run manually in that path - it runs
Directly added the path for the dll, It has the same result
stage ('Build + SonarQube analysis') {
agent {
docker {
image 'mcr.microsoft.com/dotnet/core/sdk:2.2'
}
}
steps {
dir ("app") {
withSonarQubeEnv('local') {
sh "dotnet /var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/Scanner_for_MSBuild_4.7/SonarScanner.MSBuild.dll begin /k:\"Testing-Local\""
sh "dotnet build ${env.DotnetProjectName}"
sh "dotnet var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/Scanner_for_MSBuild_4.7/SonarScanner.MSBuild.dll end"
}
}
}
}
Thanks for the help in advance.
I was able to solve this,
1. Installed the SonarScanner for dotnetcore in Jenkins Tools
The path for the sonarscanner will be the same as before
Default Path
/var/lib/jenkins/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/Scanner_for_MSBuild_4.7/SonarScanner.MSBuild.dll
2. Initialize the tool in Jenkinsfile
// Tools
MSBUILD_SQ_SCANNER_HOME = tool name: 'Scanner_for_MSBuild_4.7', type: 'hudson.plugins.sonar.MsBuildSQRunnerInstallation'
stage ('Build + SonarQube analysis')
agent {
docker {
image 'mcr.microsoft.com/dotnet/core/sdk:2.2'
args '-v ${MSBUILD_SQ_SCANNER_HOME}:/opt/sonarscanner'
}
}
steps {
dir ("app") {
withSonarQubeEnv('local') {
sh "dotnet /opt/sonarscanner/SonarScanner.MSBuild.dll begin /k:\"Testing-Local\""
sh "dotnet build ${env.DotnetProjectName}"
sh "dotnet /opt/sonarscanner/SonarScanner.MSBuild.dll end"
}
}
}
}
How it works?
I am mounting the sonarscanner to the official docker image at the path /opt/sonarscanner/
With the mounted file as an argument for docker container during initialization, now the dll is avaliable for the docker dotnet command

QT powershell error windows-build-qt-static.ps1

After 6-7 attempts to compile QT static version i used this article Building_a_static_Qt_for_Windows_using_MinGW
and again errors:
I have installed QT 5.7.
I downloaded
windows-build-qt-static.ps1 then changing the necessary lines
[CmdletBinding()]
param(
$QtSrcUrl = "https://download.qt.io/snapshots/qt/5.8/5.8.0/latest_src/qt-everywhere-opensource-src-5.8.0.7z",
$QtStaticDir = "C:\Qt\Static",
$QtVersion = "5.7",
$MingwDir = "C:\Qt\Tools\mingw530_32\bin\gcc.exe",
[switch]$NoPause = $false
)
and the error is
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.
PS C:\Users\Admin> C:\Qt\windows-build-qt-static.ps1
Building static Qt version 5.7
Using MinGW from C:\Qt\Tools\mingw530_32\bin\gcc.exe
Downloading https://download.qt.io/snapshots/qt/5.8/5.8.0/latest_src/qt-everywhere-opensource-src-5.8.0.7z ...
Expanding C:\Qt\Static\src\qt-everywhere-opensource-src-5.8.0.7z ...
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
Scanning the drive for archives:
1 file, 353390329 bytes (338 MiB)
--
Path = C:\Qt\Static\src\qt-everywhere-opensource-src-5.8.0.7z
Type = 7z
Physical Size = 353390329
Headers Size = 1959904
Method = LZMA2:24
Solid = +
Blocks = 1
Everything is Ok
Folders: 17053
Files: 155016
Size: 1670093035
Compressed: 353390329
Patching C:\Qt\Static\src\qt-everywhere-opensource-src-5.8.0\qtbase\mkspecs\win32-g++\qmake.conf ...
+ cd qtbase
+ C:\Qt\Static\src\qt-everywhere-opensource-src-5.8.0\qtbase\configure.bat -top-level -static -debug-and-release -platfo
rm win32-g++ -prefix C:\Qt\Static\5.7 -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-
sql-sqlite -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake te
sts
Please wait while bootstrapping configure ...
Perl not found in PATH. Aborting.
mingw32-make : The term 'mingw32-make' is not recognized as the name of a cmdlet, function, script file, or operable pr
ogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Qt\windows-build-qt-static.ps1:170 char:5
+ mingw32-make -k -j4
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (mingw32-make:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
mingw32-make : The term 'mingw32-make' is not recognized as the name of a cmdlet, function, script file, or operable pr
ogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Qt\windows-build-qt-static.ps1:171 char:5
+ mingw32-make -k install
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (mingw32-make:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Out-File : Could not find a part of the path 'C:\Qt\Static\5.7\mkspecs\win32-g++\qmake.conf'.
At C:\Qt\windows-build-qt-static.ps1:178 char:6
+ "# | Out-File -Append $File -Encoding Ascii
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Out-File], DirectoryNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
Please wait while bootstrapping configure ...
Perl not found in PATH. Aborting.
mingw32-make : The term 'mingw32-make' is not r .....
Out-File : Could not find a part of the path 'C:\Qt\Static\5.7\mkspecs\win32-g++\qmake.conf'.
At C:\Qt\windows-build-qt-static.ps1:178 char:6
+ "# | Out-File -Append $File -Encoding Ascii
This windows-build-qt-static.ps1 script worked for me a year ago.
Note at line 117, I just removed one * from path C:\Qt\Tools\mingw*\bin\gcc.exe between Qt\ and Tools
#-----------------------------------------------------------------------------
#
# Copyright (c) 2013-2015, Thierry Lelegard
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
#
#-----------------------------------------------------------------------------
<#
.SYNOPSIS
Build a static version of Qt for Windows.
.DESCRIPTION
This scripts downloads Qt source code, compiles and installs a static version
of Qt. It assumes that a prebuilt Qt / MinGW environment is already installed,
typically in C:\Qt. This prebuilt environment uses shared libraries. It is
supposed to remain the main development environment for Qt. This script adds
a static version of the Qt libraries in order to allow the construction of
standalone and self-sufficient executable.
This script is typically run from the Windows Explorer.
Requirements:
- Windows PowerShell 3.0 or higher.
- 7-zip.
.PARAMETER QtSrcUrl
URL of the Qt source file archive.
By default, use the latest identified version.
.PARAMETER QtStaticDir
Root directory where the static versions of Qt are installed.
By default, use C:\Qt\Static.
.PARAMETER QtVersion
The Qt version. By default, this script tries to extract the version number
from the Qt source file name.
.PARAMETER MingwDir
Root directory of the MinGW prebuilt environment. By default, use the version
which was installed by the prebuilt Qt environment.
.PARAMETER NoPause
Do not wait for the user to press <enter> at end of execution. By default,
execute a "pause" instruction at the end of execution, which is useful
when the script was run from Windows Explorer.
#>
[CmdletBinding()]
param(
$QtSrcUrl = "http://download.qt.io/official_releases/qt/5.5/5.5.1/single/qt-everywhere-opensource-src-5.5.1.7z",
$QtStaticDir = "C:\Qt\Static",
$QtVersion = "",
$MingwDir = "",
[switch]$NoPause = $false
)
# PowerShell execution policy.
Set-StrictMode -Version 3
#-----------------------------------------------------------------------------
# Main code
#-----------------------------------------------------------------------------
function Main
{
# Check that 7zip is installed. We use it to expand the downloaded archive.
[void] (Get-7zip)
# Get Qt source file name from URL.
$QtSrcFileName = Split-Path -Leaf $QtSrcUrl
# If Qt version is not specified on the command line, try to extract the value.
if (-not $QtVersion) {
$QtVersion = $QtSrcFileName -replace "`.[^`.]*$",''
$QtVersion = $QtVersion -replace 'qt-',''
$QtVersion = $QtVersion -replace 'everywhere-',''
$QtVersion = $QtVersion -replace 'opensource-',''
$QtVersion = $QtVersion -replace 'src-',''
$QtVersion = $QtVersion -replace '-src',''
}
Write-Output "Building static Qt version $QtVersion"
# Qt installation directory.
$QtDir = "$QtStaticDir\$QtVersion"
# Get MinGW root directory, if not specified on the command line.
if (-not $MingwDir) {
# Search all instances of gcc.exe from C:\Qt prebuilt environment.
$GccList = #(Get-ChildItem -Path C:\Qt\Tools\mingw*\bin\gcc.exe | ForEach-Object FullName | Sort-Object)
if ($GccList.Length -eq 0) {
Exit-Script "MinGW environment not found, no Qt prebuilt version?"
}
$MingwDir = (Split-Path -Parent (Split-Path -Parent $GccList[$GccList.Length - 1]))
}
Write-Output "Using MinGW from $MingwDir"
# Build the directory tree where the static version of Qt will be installed.
Create-Directory $QtStaticDir\src
Create-Directory $QtDir
# Download the Qt source package if not yet done.
Download-File $QtSrcUrl $QtStaticDir\src\$QtSrcFileName
# Directory of expanded packages.
$QtSrcDir = "$QtStaticDir\src\$((Get-Item $QtStaticDir\src\$QtSrcFileName).BaseName)"
# Expand archives if not yet done
Expand-Archive $QtStaticDir\src\$QtSrcFileName $QtStaticDir\src $QtSrcDir
# Patch Qt's mkspecs for static build.
$File = "$QtSrcDir\qtbase\mkspecs\win32-g++\qmake.conf"
if (-not (Select-String -Quiet -SimpleMatch -CaseSensitive "# [QT-STATIC-PATCH]" $File)) {
Write-Output "Patching $File ..."
Copy-Item $File "$File.orig"
#"
# [QT-STATIC-PATCH]
QMAKE_LFLAGS += -static -static-libgcc
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CFLAGS_RELEASE += -Os -momit-leaf-frame-pointer
DEFINES += QT_STATIC_BUILD
"# | Out-File -Append $File -Encoding Ascii
}
# Set a clean path including MinGW.
$env:Path = "$MingwDir\bin;$MingwDir\opt\bin"
# Force English locale to avoid weird effects of tools localization.
$env:LANG = "en"
# Set environment variable QT_INSTALL_PREFIX. Documentation says it should be
# used by configure as prefix but this does not seem to work. So, we will
# also specify -prefix option in configure.
$env:QT_INSTALL_PREFIX = $QtDir
# Configure, compile and install Qt.
Push-Location $QtSrcDir
& $env:SystemRoot\System32\cmd.exe /c "configure.bat -static -debug-and-release -platform win32-g++ -prefix $QtDir `
-qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sql-sqlite -no-openssl `
-opensource -confirm-license `
-make libs -nomake tools -nomake examples -nomake tests"
mingw32-make -k -j4
mingw32-make -k install
Pop-Location
# Patch Qt's installed mkspecs for static build of application.
$File = "$QtDir\mkspecs\win32-g++\qmake.conf"
#"
CONFIG += static
"# | Out-File -Append $File -Encoding Ascii
Exit-Script
}
#-----------------------------------------------------------------------------
# A function to exit this script. The Message parameter is used on error.
#-----------------------------------------------------------------------------
function Exit-Script ([string]$Message = "")
{
$Code = 0
if ($Message -ne "") {
Write-Output "ERROR: $Message"
$Code = 1
}
if (-not $NoPause) {
pause
}
exit $Code
}
#-----------------------------------------------------------------------------
# Silently create a directory.
#-----------------------------------------------------------------------------
function Create-Directory ([string]$Directory)
{
[void] (New-Item -Path $Directory -ItemType "directory" -Force)
}
#-----------------------------------------------------------------------------
# Download a file if not yet present.
# Warning: If file is present but incomplete, do not download it again.
#-----------------------------------------------------------------------------
function Download-File ([string]$Url, [string]$OutputFile)
{
$FileName = Split-Path $Url -Leaf
if (-not (Test-Path $OutputFile)) {
# Local file not present, start download.
Write-Output "Downloading $Url ..."
try {
$webclient = New-Object System.Net.WebClient
$webclient.DownloadFile($Url, $OutputFile)
}
catch {
# Display exception.
$_
# Delete partial file, if any.
if (Test-Path $OutputFile) {
Remove-Item -Force $OutputFile
}
# Abort
Exit-Script "Error downloading $FileName"
}
# Check that the file is present.
if (-not (Test-Path $OutputFile)) {
Exit-Script "Error downloading $FileName"
}
}
}
#-----------------------------------------------------------------------------
# Get path name of 7zip, abort if not found.
#-----------------------------------------------------------------------------
function Get-7zip
{
$Exe = "C:\Program Files\7-Zip\7z.exe"
if (-not (Test-Path $Exe)) {
$Exe = "C:\Program Files (x86)\7-Zip\7z.exe"
}
if (-not (Test-Path $Exe)) {
Exit-Script "7-zip not found, install it first, see http://www.7-zip.org/"
}
$Exe
}
#-----------------------------------------------------------------------------
# Expand an archive file if not yet done.
#-----------------------------------------------------------------------------
function Expand-Archive ([string]$ZipFile, [string]$OutDir, [string]$CheckFile)
{
# Check presence of expected expanded file or directory.
if (-not (Test-Path $CheckFile)) {
Write-Output "Expanding $ZipFile ..."
& (Get-7zip) x $ZipFile "-o$OutDir" | Select-String -Pattern "^Extracting " -CaseSensitive -NotMatch
if (-not (Test-Path $CheckFile)) {
Exit-Script "Error expanding $ZipFile, $OutDir\$CheckFile not found"
}
}
}
#-----------------------------------------------------------------------------
# Execute main code.
#-----------------------------------------------------------------------------
. Main

PowerShell script not working on server

I have a simple PowerShell script in which I try to write some log data.
The script that's not working:
Add-Content -Path C:\temp\logg.txt -Value $file.FullName
This line I placed in the middle of the script and I never get any text in the logg.txt. The Script executes fine except this, it compiles some files to a zip file.
This is on a Windows server.
If I, however, run the same script on my local machine, Win7, it does work!?
So I think it must be something with the server but I can't figure it out. Am using -ExecutionPolicy Bypass when I run the script.
EDIT: more info.
The script is called from an ASP.NET webpage:
Process.Start("Powershell.exe", "-ExecutionPolicy Bypass -Command ""& {" & destinationFolderRoot.Replace("\\", "\") & "\scriptParameters.ps1}""")
BaseZipScript:
function New-Zip
{
param([string]$zipfilename)
Set-Content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
function Add-Zip
{
param([string]$zipfilename)
if(-not (Test-Path($zipfilename)))
{
Set-Content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
$shellApplication = New-Object -COM Shell.Application
$zipPackage = $shellApplication.NameSpace($zipfilename)
foreach($file in $input)
{
$zipPackage.CopyHere($file.FullName)
Add-Content -Path "C:\temp\logg.txt" -Value $file.FullName
Start-Sleep -Milliseconds 750
}
}
scriptParameters1:
. "C:\temp\multiDownload\baseZipScript.ps1"
New-Zip c:\temp\multiDownload\user379\2016-09-15_14.39\files_2016-09-15_14.39.zip
dir c:\temp\multiDownload\user379\2016-09-15_14.39\tempCopy\*.* -Recurse |
Add-Zip c:\temp\multiDownload\user379\2016-09-15_14.39\files_2016-09-15_14.39.zip
Start-sleep -milliseconds 250
exit
As I said earlier the script works on local machine and also on the server, e.g. the files are being zipped, except that on the server nothing is logged in logg.txt.
Though the logg.txt works and exists on the server because the webpage also log some info there and that is being written.
Update:
As the comments guessed it was as simple as write access to the file. Though, it is kind of wierd because all files are created from the webservice if they doesn't exists? Any how, it works now. Thx! : )

MSB4018 Error Visual Studio 2015 ASP.Net and Error Publish Web App to Azure

I am working with Visual Studio 2015 Community with Azure 2.9 For the first time. I tried creating a brand new ASP.Net Web Application. The default template build and viewed in the Browser with no issues.
I tried publishing the site using Azure. When doing so I get this error
The "InvokePowerShell" task failed unexpectedly.
System.Management.Automation.CommandNotFoundException: The term '[cmdletbinding(SupportsShouldProcess=$true)]
param($publishProperties, $packOutput, $nugetUrl)
# to learn more about this file visit http://go.microsoft.com/fwlink/?LinkId=524327
$publishModuleVersion = '1.0.1'
function Get-VisualStudio2015InstallPath{
[cmdletbinding()]
param()
process{
$keysToCheck = #('hklm:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0',
'hklm:\SOFTWARE\Microsoft\VisualStudio\14.0',
'hklm:\SOFTWARE\Wow6432Node\Microsoft\VWDExpress\14.0',
'hklm:\SOFTWARE\Microsoft\VWDExpress\14.0'
)
[string]$vsInstallPath=$null
foreach($keyToCheck in $keysToCheck){
if(Test-Path $keyToCheck){
$vsInstallPath = (Get-itemproperty $keyToCheck -Name InstallDir -ErrorAction SilentlyContinue | select -ExpandProperty InstallDir -ErrorAction SilentlyContinue)
}
if($vsInstallPath){
break;
}
}
$vsInstallPath
}
}
$vsInstallPath = Get-VisualStudio2015InstallPath
$publishModulePath = "{0}Extensions\Microsoft\Web Tools\Publish\Scripts\{1}\" -f $vsInstallPath, $publishModuleVersion
if(!(Test-Path $publishModulePath)){
$publishModulePath = "{0}VWDExpressExtensions\Microsoft\Web Tools\Publish\Scripts\{1}\" -f $vsInstallPath, $publishModuleVersion
}
$defaultPublishSettings = New-Object psobject -Property #{
LocalInstallDir = $publishModulePath
}
function Enable-PackageDownloader{
[cmdletbinding()]
param(
$toolsDir = "$env:LOCALAPPDATA\Microsoft\Web Tools\Publish\package-downloader-$publishModuleVersion\",
$pkgDownloaderDownloadUrl = 'http://go.microsoft.com/fwlink/?LinkId=524325') # package-downloader.psm1
process{
if(get-module package-downloader){
remove-module package-downloader | Out-Null
}
if(!(get-module package-downloader)){
if(!(Test-Path $toolsDir)){ New-Item -Path $toolsDir -ItemType Directory -WhatIf:$false }
$expectedPath = (Join-Path ($toolsDir) 'package-downloader.psm1')
if(!(Test-Path $expectedPath)){
'Downloading [{0}] to [{1}]' -f $pkgDownloaderDownloadUrl,$expectedPath | Write-Verbose
(New-Object System.Net.WebClient).DownloadFile($pkgDownloaderDownloadUrl, $expectedPath)
}
if(!$expectedPath){throw ('Unable to download package-downloader.psm1')}
'importing module [{0}]' -f $expectedPath | Write-Output
Import-Module $expectedPath -DisableNameChecking -Force
}
}
}
function Enable-PublishModule{
[cmdletbinding()]
param()
process{
if(get-module publish-module){
remove-module publish-module | Out-Null
}
if(!(get-module publish-module)){
$localpublishmodulepath = Join-Path $defaultPublishSettings.LocalInstallDir 'publish-module.psm1'
if(Test-Path $localpublishmodulepath){
'importing module [publish-module="{0}"] from local install dir' -f $localpublishmodulepath | Write-Verbose
Import-Module $localpublishmodulepath -DisableNameChecking -Force
$true
}
}
}
}
try{
if (!(Enable-PublishModule)){
Enable-PackageDownloader
Enable-NuGetModule -name 'publish-module' -version $publishModuleVersion -nugetUrl $nugetUrl
}
'Calling Publish-AspNet' | Write-Verbose
# call Publish-AspNet to perform the publish operation
Publish-AspNet -publishProperties $publishProperties -packOutput $packOutput
}
catch{
"An error occurred during publish.`n{0}" -f $_.Exception.Message | Write-Error
}' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
at System.Management.Automation.Runspaces.AsyncResult.EndInvoke()
at System.Management.Automation.PowerShell.EndInvoke(IAsyncResult asyncResult)
at Microsoft.Web.Publishing.Tasks.InvokePowerShell.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() WebApplication1 0
I am assuming I missed something in my install? Anyone know what this error is or how to get passed it?
I upvoted this in the past, then apparently found the answer somewhere else, then forgot the answer again and ended up here again.
Adding <AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
in the csproj on the right PropertyGroup fixed the problem for me.

Capistrano not really restarting a server?

I use Capistrano 2.15 and Nginx running on DigitalOcean droplet.
Sometimes, especially, when I install new gems or run migrations I need to hard reset my droplet to take my changes into effect.
This does not apply, if I simply change code somewhere, when running
cap deploy:restart
is fine.
Also, when I log in into my machine and run
service nginx restart
it does not help to capture new migrations.
deploy.rb
require "rvm/capistrano"
set :rvm_ruby_string, 'default'
set :rvm_type, :user
require "bundler/capistrano"
server "xx.xx.xx.xx", :web, :app, :db, primary: true
set :application, "xxx"
set :user, "deployer"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git#bitbucket.org:xxx/#{application}.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
desc "reload the database with seed data"
task :seed do
run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{rails_env}"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
desc "tail production log files"
task :tail_logs, :roles => :app do
trap("INT") { puts 'Interupted'; exit 0; }
run "tail -f #{shared_path}/log/unicorn.log" do |channel, stream, data|
puts # for an extra line break before the host name
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
end
namespace :assets do
task :symlink, roles: :web do
run ("rm -rf #{latest_release}/public/assets &&
mkdir -p #{latest_release}/public &&
mkdir -p #{shared_path}/assets &&
ln -s #{shared_path}/assets #{latest_release}/public/assets")
end
end
namespace :uploads do
desc <<-EOD
Creates the upload folders unless they exist
and sets the proper upload permissions.
EOD
task :setup, :except => { :no_release => true } do
dirs = [File.join(shared_path,'uploads' )]
run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
end
desc <<-EOD
[internal] Creates the symlink to uploads shared folder
for the most recently deployed version.
EOD
task :symlink, :except => { :no_release => true } do
run "rm -rf #{release_path}/public/uploads"
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end
desc <<-EOD
[internal] Computes uploads directory paths
and registers them in Capistrano environment.
EOD
task :register_dirs do
set :uploads_dirs, %w(public/uploads)
set :shared_children, fetch(:shared_children) + fetch(:uploads_dirs)
end
after "deploy:finalize_update", "uploads:symlink"
on :start, "uploads:register_dirs"
end
Here is unicorn_init:
http://pastebin.com/cm6NCupK
when you deploy you use cap:deploy?
you use unicorn or passenger?
please paste your code here deploy.rb unicorn.rb(if you use unicorn) and unicorn_init.sh(or your sh file you create symlink from)
last question you use before_fork after_fork?(for zero downtime deploy?)

Resources