【问题标题】:MSB4018 Error Visual Studio 2015 ASP.Net and Error Publish Web App to AzureMSB4018 错误 Visual Studio 2015 ASP.Net 和错误将 Web 应用程序发布到 Azure
【发布时间】:2016-04-04 03:02:56
【问题描述】:

我是第一次使用带有 Azure 2.9 的 Visual Studio 2015 社区。我尝试创建一个全新的 ASP.Net Web 应用程序。在浏览器中构建和查看默认模板没有问题。

我尝试使用 Azure 发布网站。这样做时我收到此错误

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   

我假设我在安装过程中遗漏了什么?任何人都知道这个错误是什么或如何通过它?

【问题讨论】:

  • 你是如何发布这个的?您是否访问过 Azure 门户并下载了发布配置文件?
  • 检查是否已安装 Azure PowerShell。如果它已经存在,请尝试重新安装。

标签: asp.net azure azure-web-app-service publish azure-powershell


【解决方案1】:

我过去曾对此投过赞成票,然后显然在其他地方找到了答案,然后又忘记了答案,又回到了这里。


添加&lt;AutoParameterizationWebConfigConnectionStrings&gt;False&lt;/AutoParameterizationWebConfigConnectionStrings&gt; 在右侧 PropertyGroup 的 csproj 中为我解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多