简体   繁体   English

无法在 VS2017 中使用 Microsoft.Build.Evaluation

[英]Can't use Microsoft.Build.Evaluation in VS2017

I built a Web Forms website using VS2015 where I user Microsoft.Build.Evaluation so that I can grammatically go through the files in my project.我使用 VS2015 构建了一个 Web 表单网站,我在其中使用Microsoft.Build.Evaluation以便我可以在语法上浏览项目中的文件。 When using VS2017 I get this error:使用 VS2017 时出现此错误:

Microsoft.Build.Exceptions.InvalidProjectFileException: 'The imported project "C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v15.0\\WebApplications\\Microsoft.WebApplication.targets" was not found. Microsoft.Build.Exceptions.InvalidProjectFileException: '未找到导入的项目“C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v15.0\\WebApplications\\Microsoft.WebApplication.targets”。 Confirm that the path in the declaration is correct, and that the file exists on disk.确认声明中的路径正确,并且该文件存在于磁盘上。 C:\\Users\\MyUser\\Source\\Workspaces\\MyProject TFVC2\\Gemstar\\MyProject.csproj' C:\\Users\\MyUser\\Source\\Workspaces\\MyProject TFVC2\\Gemstar\\MyProject.csproj'

Here is my code:这是我的代码:

using Microsoft.Build.Evaluation;

Project project = new Project();
if (ProjectCollection.GlobalProjectCollection.GetLoadedProjects(mPath + "MyProject.csproj").Count == 0)
{
    project = new Project(mPath + "MyProject.csproj");
}
else
{
    project = ProjectCollection.GlobalProjectCollection.GetLoadedProjects(mPath + "MyProject.csproj").FirstOrDefault();
}

I want to mention that I installed BuildTools for VS2017 from https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15我想提一下,我从https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15安装了 BuildTools for VS2017

Mac OS - Mac 操作系统 -
I resolved it by installing the latest version of Mono.我通过安装最新版本的 Mono 解决了这个问题。

  1. Installing Mono on macOS.在 macOS 上安装 Mono。
  2. Search "omnisharp" in settings (command + ',').在设置中搜索“omnisharp”(命令 + ',')。
  3. Changed the setting Omnisharp: Use Global Mono to always .将设置Omnisharp: Use Global Mono更改为always
  4. Reload the vscode.重新加载 vscode。

Can't use Microsoft.Build.Evaluation in VS2017无法在 VS2017 中使用 Microsoft.Build.Evaluation

It seems the old value of MSBuildExtensionsPath32 set in the Microsoft.Build.Evaluation .似乎MSBuildExtensionsPath32的旧值设置在Microsoft.Build.Evaluation

According to the error info:根据错误信息:

The imported project " C:\\Program Files(x86)\\MSBuild\\Microsoft\\VisualStudio \\v15.0\\WebApplications\\Microsoft.WebApplication.targets" was not found.未找到导入的项目“ C:\\Program Files(x86)\\MSBuild\\Microsoft\\VisualStudio \\v15.0\\WebApplications\\Microsoft.WebApplication.targets”。

The import path for Microsoft.WebApplication.targets is not correct. Microsoft.WebApplication.targets的导入路径不正确。

In the project file .csproj , we notice following import:在项目文件.csproj ,我们注意到以下导入:

  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

So the value for MSBuildExtensionsPath32 is C:\\Program Files (x86)\\MSBuild in the Microsoft.Build.Evaluation , which is not correct for Visual Studio 2017.因此,对于价值MSBuildExtensionsPath32C:\\Program Files (x86)\\MSBuildMicrosoft.Build.Evaluation ,这是不正确的Visual Studio 2017年。

The value of MSBuildExtensionsPath32 for Visual Studio 2017 should be: Visual Studio 2017 的MSBuildExtensionsPath32值应为:

BuildTool Installed:已安装构建工具:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0

Visual Studio Installed:已安装的 Visual Studio:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0

To resolve this issue, you could verride the value in your project file:要解决此问题,您可以验证项目文件中的值:

<PropertyGroup>
    <MSBuildExtensionsPath32>C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0</MSBuildExtensionsPath32>
  </PropertyGroup>

  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

See the similar issue for some more details.有关更多详细信息,请参阅类似问题

Hope this helps.希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Microsoft.Build.Evaluation发布数据库项目(.sqlproj) - Using Microsoft.Build.Evaluation to publish a database project (.sqlproj) 使用 Microsoft.Build.Evaluation(而不是 Engine)以编程方式修改 csproj 文件 - Modify programatically csproj files with Microsoft.Build.Evaluation (instead of Engine) 在VS2017版本的Microsoft Store中将文件夹声明为语言中性 - Declare folder as language neutral in VS2017 build for the Microsoft Store 如何将VS2017与Unity 2018一起使用 - How can I use VS2017 with Unity 2018 使用Microsoft.Build程序集构建VS2017解决方案:执行期间出错 - Build VS2017 solution with Microsoft.Build assemblies : error during execution Microsoft.Build.Evaluation(快进到 2021 年)的正确用法是什么? - What's the correct usage of Microsoft.Build.Evaluation (fast forward to 2021)? 为什么Microsoft.Build.Evaluation在64位PC上将$(ProgramFiles)评估为“ c:\\ program files”? - Why does Microsoft.Build.Evaluation evaluate $(ProgramFiles) as “c:\program files” on 64 bit PC? 如何使用 microsoft.build.evaluation 以编程方式添加新的 dll 参考 - How to add new dll reference programmatically using microsoft.build.evaluation VS2017 WinForms 无法更新服务参考 - VS2017 WinForms can't update service reference VS 2017,Microsoft.Build.Framework上的EF 6.13 add-migration抛出异常 - EF 6.13 add-migration throw exception on VS2017, Microsoft.Build.Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM