首页 > 解决方案 > MSBuild 尝试将 .NET 核心目标用于 .NET Framework 项目

问题描述

我有 .NET 4.6 Web 应用程序,它在我的机器上构建良好 - 来自 Visual Studio 和 MSBuild 命令行。在不同的机器上(构建代理,安装了 Visual Studio),我得到如下构建错误:

[restore] C:\blabla\myapp.csproj(430,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\2.1.100\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

在 csproj 文件中,导入看起来像这样

<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

所以似乎出于某种原因VSToolsPath设置为。C:\Program Files\dotnet\sdk\2.1.100\Microsoft\VisualStudio\v15.0在我看来,就像 MSBuild 正在尝试使用 .NET Core “工具”。这可能是什么原因以及如何解决?

编辑:添加构建命令(bat 文件):

set PATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin";%PATH%

msbuild "mysolution.sln" /t:Rebuild /p:Configuration=Release /p:Platform="Any CPU" /p:TargetProfile="ProdCloud"

标签: .netmsbuild.net-core

解决方案


推荐阅读