本文介绍了Azure管道:未找到错误MSB4019 WebApplication.targets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Episerver合金项目,该项目在设置了一些nuget程序包后可以在Visual Studio中构建并正常运行,并且可以从VS部署到Azure并在Azure中运行而没有问题.

I created an episerver alloy project, which builds and runs fine in visual studio after setting up some nuget packages, and I can deploy to azure and run in azure from VS without issue.

我现在正在尝试使构建能够在管道中正常工作.

I am now trying to get the build to work in pipelines.

按照说明进行操作,我添加了一个"nuget restore"任务,并将其指向NuGet.config.这行得通.

Following the instructions, I added a "nuget restore" task, and pointed it at a NuGet.config.This works.

然后进入构建阶段,并给出:

Then it gets to the build stage, and gives:

D:\ a \ 1 \ s \ DxcAlloy.csproj(335,3):错误MSB4019:导入的项目"C:\ Program Files \ dotnet \ sdk \ 3.1.202 \ Microsoft \ VisualStudio \ v16.0 \找不到"WebApplications \ Microsoft.WebApplication.targets".确认导入声明"C:\ Program Files \ dotnet \ sdk \ 3.1.202 \ Microsoft \ VisualStudio \ v16.0 \ WebApplications \ Microsoft.WebApplication.targets"中的表达式正确,并且该文件在磁盘上.

D:\a\1\s\DxcAlloy.csproj(335,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.1.202\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.202\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk.

我不知道该如何调试.一些帖子说,如果您没有安装Visual Studio,可能会发生错误,但是我无法在Azure管道上安装Visual Studio ...

I have no idea how to debug this. Some posts say that error can happen if you dont have visual studio installed, but I cant install visual studio on azure pipelines...

我删除了现有的".net restore"任务,因为它失败了,我猜我只需要我的nuget恢复-这是一个猜测.

I removed the existing ".net restore" task, as it failed, and am guessing that just my nuget restore is all I need - this is a guess.

管道代理规范"为vs2017-win16

The pipeline "agent specification" is vs2017-win16

该项目是在VS 2019中创建的.

The project was created in VS 2019.

无奈之下,我添加了一个使用.NET core"任务,并将版本设置为缺少构建抱怨的版本,即3.1.202.

In desperation, I added a "Use .NET core" task, and set the version to the one which build is complaining is missing, i.e. 3.1.202.

这没有帮助.

有什么想法吗?

推荐答案

如果使用 dotnet build 任务构建项目..csproj文件中的以下配置将评估为 C:\ Program Files \ dotnet \ sdk \ 3.1.202 \ Microsoft \ VisualStudio \ v16.0 \ WebApplications \ Microsoft.WebApplication.targets (从错误中看到)

If you build your project using dotnet build task. Below configuration in your .csproj file will be evaluated to C:\Program Files\dotnet\sdk\3.1.202\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets (What you see from the error)

< VSToolsPath Condition ='$(VSToolsPath)'==''"> $(MSBuildExtensionsPath32)\ Microsoft \ VisualStudio \ v16.0</VSToolsPath><导入项目="$(VSToolsPath)\ WebApplications \ Microsoft.WebApplication.targets"/>

Microsoft.WebApplication.targets通常存在于以下位置.这就是为什么它会错误提示 ...找不到Microsoft.WebApplication.targets .

Microsoft.WebApplication.targets usually exists in below location. That is why it errors out ...Microsoft.WebApplication.targets not found.

在Visual Studio 2019中"C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Enterprise \ MSBuild \ Microsoft \ VisualStudio \ v16.0 \ WebApplications \ Microsoft.WebApplication.targets"

In Visual Studio 2019 "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets"

上述问题的解决方法是使用 Msbuid 任务或使用Visual Studio构建任务来构建您的项目.参见以下示例:

The workaround for above issue is using Msbuid task or Visual Studio build task to build your projects. See below example:

- task: VSBuild@1
    inputs:
      solution: '**/*.csproj'
    enabled: true

对于您的情况,还需要将代理规范设置为代理 windows-latest .对于Visual Studio 2019( v16.0 )仅安装在代理 windows-latest 中.

For your case, you also need to set agent specification to agent windows-latest. For visual studio 2019(v16.0) is only installed in agent windows-latest.

如果必须在代理"vs2017-win16"上运行管道(仅安装了Visual Studio 2017( v15.0 )).您需要将.csproj文件中的 VSToolsPath 更改为< VSToolsPath Condition ='$(VSToolsPath)'==''"&$; $(MSBuildExtensionsPath32)\ Microsoft \ VisualStudio \v15.0</VSToolsPath>

If you have to run your pipeline on agent "vs2017-win16" (only visual studio 2017(v15.0) is installed). You need to change the VSToolsPath in the .csproj file to <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v15.0</VSToolsPath>

如果必须使用 dotnet build 来构建项目.您可以将csproj文件中的导入路径硬编码为解决方法.

If you have to use dotnet build to build your projects. You can hard code the import path in csproj file as workaround.

<导入项目="C:\ Program Files(x86)\ Microsoft Visual Studio \ 2019 \ Enterprise \ MSBuild \ Microsoft \ VisualStudio \ v16.0 \ WebApplications \ Microsoft.WebApplication.targets"/>

这篇关于Azure管道:未找到错误MSB4019 WebApplication.targets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 03:26