VSTS无法建立;错误MSB4184:表达式" [System.IO.Path] :: GetDirectoryName('')"无法评估。这条道路不是合法的形式

时间:2017-05-22 15:27:44

标签: visual-studio-2017 azure-pipelines

我正在尝试构建我的.Net Core解决方案,我收到的这些错误消息是我无法弄清楚的;

2017-05-22T14:30:56.2490242Z _TransformWebConfig:
2017-05-22T14:30:56.2490242Z   No web.config found. Creating 'd:\a\1\s\SIR\obj\Release\net452\win7-x86\PubTmp\Out\web.config'
2017-05-22T14:30:56.2830092Z ##[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeployPackage.targets(124,7): Error MSB4184: The expression "[System.IO.Path]::GetDirectoryName('')" cannot be evaluated. The path is not of a legal form.
2017-05-22T14:30:56.2830092Z ##[debug]Processed: ##vso[task.logissue type=Error;sourcepath=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeployPackage.targets;linenumber=124;columnnumber=7;code=MSB4184;]The expression "[System.IO.Path]::GetDirectoryName('')" cannot be evaluated. The path is not of a legal form.
2017-05-22T14:30:56.2830092Z C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeployPackage.targets(124,7): error MSB4184: The expression "[System.IO.Path]::GetDirectoryName('')" cannot be evaluated. The path is not of a legal form. [d:\a\1\s\SIR\Properties.API.csproj]
2017-05-22T14:30:56.2830092Z ##[debug]Processed: ##vso[task.logdetail id=43c372fe-1339-4917-bfb2-2d3438740b01;parentid=e8365874-6f54-4a8c-a31f-62c69bcfdb57;type=Build;result=Failed;finishtime=2017-05-22T14:30:56.2790105Z;progress=100;state=Completed;parentid=e8365874-6f54-4a8c-a31f-62c69bcfdb57;name=;]
2017-05-22T14:30:56.2830092Z Done Building Project "d:\a\1\s\SIR\Properties.API.csproj" (default targets) -- FAILED.

4 个答案:

答案 0 :(得分:3)

请参阅以下步骤:

  1. 添加NuGet Installer(4.0.0)任务以恢复包
  2. 添加Visual Studio构建任务(解决方案:**\*.sln; MSBuild参数:/t:[projects] /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\App1")。 注意:项目是该解决方案中的一般.net框架项目,例如/ t:project1; project2
  3. 添加.NET Core任务(命令:publish;取消选中发布Web项目选项;项目:$(build.sourcesdirectory)/*Core*.csproj对应您的核心项目名称);参数:-o "$(build.artifactstagingdirectory)\\App2"
  4. 添加发布构建工件任务

答案 1 :(得分:0)

使用缺少DesktopBuildPackageLocation属性的发布配置文件构建msdeploy软件包时会发生此错误。

确保您的发布配置文件包含此属性,也可以与examples listed in the websdk repo进行交叉检查。

作为参考,示例msdeploy包发布配置文件(来自上面的链接)如下所示:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>Package</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <DesktopBuildPackageLocation>c:\DeployedApp\WebDeployPackage.zip</DesktopBuildPackageLocation>
    <DeployIisAppPath>Default Web Site/WebAppWithDB</DeployIisAppPath>
  </PropertyGroup>
</Project>

答案 2 :(得分:0)

我遇到了与VSTS中的默认ASP核心模板Build相同的问题。我没有发布配置文件,因为我通过VSTS CI模板管理构建。我发现SO post中的答案解决了我的问题。

我用.NET Core(PREVIEW)任务替换了我的Visual Studio Build任务,并使用了dotnet publish命令。

.Net Core Task

Build Arguments

答案 3 :(得分:0)

此问题已修复:https://github.com/aspnet/websdk/issues/106

在VSTS中使用的示例命令行和语法(核心模板应该已经具有此功能):https://github.com/vijayrkn/ASPNetPublishSamples/blob/bff9f78d796668dc07d5e28a8b93531caade839c/Publish.cmd#L102-L127