6
votes

I am trying to deploy a web app to Azure via Visual Studio Team Services (previously Visual Studio Online) release and deploy system. This was working fine until yesterday when I encountered the following error:

[error]The term 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1' 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.

I am using the following script for publishing:

PublishAspNet5WebApp.ps1

param($websiteName, $packOutput)

$website = Get-AzureWebsite -Name $websiteName

# get the scm url to use with MSDeploy.  By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]


$publishProperties = @{'WebPublishMethod'='MSDeploy';
                        'MSDeployServiceUrl'=$msdeployurl;
                        'DeployIisAppPath'=$website.Name;
                        'Username'=$website.PublishingUsername;
                        'Password'=$website.PublishingPassword}


$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"


. $publishScript -publishProperties $publishProperties  -packOutput $packOutput

I then checked on Kudu if the default-publish.ps1 file actually exists at path:

$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"

and I found that the entire Web Tools folder doesn't exist.

Is this a very recent change? How can I work around it? I assume changing the script location won't just magically work.

Thanks.

2
I think we have the same issue here too. Our publish script was working yesterday but is not working today, and we have the same error.areve
Same here, this stoped woring sometime during the last two weeks.Gustav Gahm
I'm having this same problem but with a microsoft library .... 'Microsoft.TeamFoundation.DistributedTask.Task.Common' was not loaded because no valid module file was found in any module directory and then under that it says The term 'Get-LocalizedString' 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. it was working seriously five seconds ago... i made a comment and now its not working... any help please?Moi Hawk

2 Answers

6
votes

The work around that worked for me was to copy "default-publish.ps1" file which is already on my local and place it under the project's folder.

Then, I changed the publish script to use this file instead:

$publishScript = "$PSScriptRoot\default-publish.ps1"
#$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"

EDIT:

For those who don't have "default-publish.ps1" file on their local, here it is:

[cmdletbinding(SupportsShouldProcess=$true)]
param($publishProperties, $packOutput, $nugetUrl)

$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
}
0
votes

The script has changed in VS 2017 at least. Use these two:

default-publish: [cmdletbinding(SupportsShouldProcess=$true)] param($publishProperties=@{}, $packOutput, $pubProfilePath)

# to learn more about this file visit https://go.microsoft.com/fwlink/?LinkId=524327

try{
    if ($publishProperties['ProjectGuid'] -eq $null){
        $publishProperties['ProjectGuid'] = ''
    }
$publishModulePath = Join-Path (Split-Path $MyInvocation.MyCommand.Path) 'publish-module.psm1'
Import-Module $publishModulePath -DisableNameChecking -Force

# call Publish-AspNet to perform the publish operation
Publish-AspNet -publishProperties $publishProperties -packOutput $packOutput -pubProfilePath $pubProfilePath
}
catch{
    "An error occurred during publish.`n{0}" -f $_.Exception.Message | Write-Error
}

publish-module.psm1 is too big for me too post

The location is: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\ide\Extensions\Microsoft\Web Tools\Publish\Scripts\1.2.0