C# 外部 VS2013 构建错误“错误 MSB4019:未找到导入的项目 <路径>”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19718281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 15:43:13  来源:igfitidea点击:

External VS2013 build error "error MSB4019: The imported project <path> was not found"

c#web-applicationsvisual-studio-2013buildvisual-build-professional

提问by Sarah Weinberger

I am building a project through the command line and not inside Visual Studio 2013. Note, I had upgraded my project from Visual Studio 2012 to 2013. The project builds fine inside the IDE. Also, I completely uninstalled VS2012 first, rebooted, and installed VS2013. The only version of Visual Studio that I have is 2013 Ultimate.

我正在通过命令行而不是在 Visual Studio 2013 中构建项目。请注意,我已将我的项目从 Visual Studio 2012 升级到 2013。该项目在 IDE 中构建良好。另外,我首先完全卸载了VS2012,重新启动并安装了VS2013。我拥有的唯一版本的 Visual Studio 是 2013 Ultimate。

ValidateProjects:
    39>path_to_project.csproj(245,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.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.
    39>Done Building Project "path_to_project.csproj" (Clean target(s)) -- FAILED.

Here are the two lines in question:

这是有问题的两行:

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

The original second line was v10.0, but I manually changed that to v12.0.

最初的第二行是 v10.0,但我手动将其更改为 v12.0。

$(VSToolsPath) elongates from what I see to the v11.0 (VS2012) folder, which obviously is not there anymore. The path should have been to v12.0.

$(VSToolsPath) 从我看到的地方延伸到 v11.0 (VS2012) 文件夹,这显然已经不存在了。路径应该是 v12.0。

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\WebApplications\

I tried specifying VSToolsPath in my system environment variables table, but the external build utility still uses v11.0. I tried searching through the registry and that came up with nothing.

我尝试在系统环境变量表中指定 VSToolsPath,但外部构建实用程序仍然使用 v11.0。我尝试在注册表中搜索,但一无所获。

Sadly, I do not see any easy way to get the exact command line used. I use a build tool.

可悲的是,我没有看到任何简单的方法来使用确切的命令行。我使用构建工具。

Thoughts?

想法?

采纳答案by giammin

I had the same issue and find an easier solution

我遇到了同样的问题并找到了更简单的解决方案

It is due to Vs2012 adding the following to the csproj file:

这是由于 Vs2012 在 csproj 文件中添加了以下内容:

<PropertyGroup>
  <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
  <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

You can safely remove that part and your solution will build.

您可以安全地移除该部分,然后您的解决方案就会构建。

As Sielu pointed outyou have to ensure that the .proj file begin with <Project ToolsVersion="12"otherwise the next time you open the project with visual studio 2010, it will add the removed node again.

正如Sielu 指出的那样,您必须确保 .proj 文件以 .proj 文件开头,<Project ToolsVersion="12"否则下次使用 Visual Studio 2010 打开项目时,它将再次添加已删除的节点。

Otherwise, if you need to use webdeploy or you use a build server, the above solution will not work but you can specify the VisualStudioVersionproperty in your build script:

否则,如果您需要使用 webdeploy 或使用构建服务器,则上述解决方案将不起作用,但您可以VisualStudioVersion在构建脚本中指定该属性:

msbuild myproject.csproj /p:VisualStudioVersion=12.0

or edit your build definition:

或编辑您的构建定义:

edit build definition to specify the <code>VisualStudioVersion</code>property

编辑构建定义以指定 <code>VisualStudioVersion</code>属性

回答by Sarah Weinberger

I just received a response from Kinook, who gave me a link:

我刚刚收到 Kinook 的回复,他给了我一个链接

Basically, I need to call the following prior to bulding. I guess Visual Studio 2013 does not automatically register the environment first, but 2012 did, or I did and forgot.

基本上,我需要在 bulding 之前调用以下内容。我猜 Visual Studio 2013 不会先自动注册环境,但是 2012 会,或者我做了然后忘记了。

call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86

Hopefully, this post helps someone else.

希望这篇文章可以帮助其他人。

回答by Sarah Weinberger

I was using an external build utility. Think of something like Ants, if I understand the product correctly, just a commercial version. I had to contact the manufacturer for the answer.

我正在使用外部构建实用程序。想想像蚂蚁这样的东西,如果我对产品的理解正确的话,只是一个商业版本。我不得不联系制造商以获得答案。

As it turns out, there is a global macro in the project, DEVSTUDIO_NET_DIR. I had to change the path to .Net there. They list various visual studio versions as "Actions", which through me off, but all roads lead back to that one global variable behind the scenes. I would list that as a defect against the product, if I had my way, unless I am missing something in my understanding. Correcting the path there fixed the build problem.

事实证明,项目中有一个全局宏,DEVSTUDIO_NET_DIR。我不得不在那里更改 .Net 的路径。他们将各种 Visual Studio 版本列为“Actions”,通过我关闭,但所有道路都回到幕后的那个全局变量。如果我按照自己的方式,我会将其列为产品缺陷,除非我在理解中遗漏了某些内容。更正那里的路径修复了构建问题。

回答by Steve

Running this in the commandline will fix the problem also. SETX VisualStudioVersion "12.0"

在命令行中运行它也可以解决这个问题。SETX VisualStudio版本“12.0”

回答by Scott

I had this problem for our FSharp targets (FSharpTargetsPath was empty).

我的 FSharp 目标有这个问题(FSharpTargetsPath 为空)。

Many of the paths are built with reference to the VS version.

许多路径是参考 VS 版本构建的。

For various reasons, our build runs with system privileges, and the environment variable "VisualStudioVersion" was only set (by the VS 2013 installer) at the "user" level - which is fair enough.

由于各种原因,我们的构建以系统权限运行,并且环境变量“VisualStudioVersion”仅在“用户”级别设置(由 VS 2013 安装程序) - 这足够公平。

Ensure that the "VisualStudioVersion" environment variable is set to "12.0" at the level (System or User) that you are running at.

确保在您运行的级别(系统或用户)将“ VisualStudioVersion”环境变量设置为“ 12.0”。

回答by Mukund

you will find

你会找到

C:\Program Files  (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets 

in csproj file for which this error is appearing. Just remove this from csproj and then build.

在出现此错误的 csproj 文件中。只需从 csproj 中删除它,然后构建。

回答by Ralph Jansen

I had this too and you can fix it by setting the tools version in your build definition.

我也有这个,你可以通过在你的构建定义中设置工具版本来修复它。

This is very easy to do. Open your build definition and go to the "Process" page. Then under the "3. Advanced" group you have a property called "MSBuild Arguments". Place the parameter there with the following syntax

这很容易做到。打开您的构建定义并转到“流程”页面。然后在“ 3. Advanced”组下,您有一个名为“ MSBuild Arguments”的属性。使用以下语法将参数放在那里

/p:VisualStudioVersion=12.0 

If you have more parameters, separate them with a space and not a comma.

如果您有更多参数,请用空格而不是逗号分隔它们。

回答by Kim Ki Won

If you migrate Visual Studio 2012 to 2013, then open *.csprorj project file with edior.
and check 'Project' tag's ToolsVersion element.

如果您将 Visual Studio 2012 迁移到 2013,则使用 edior 打开 *.csprorj 项目文件。
并检查“项目”标签的 ToolsVersion 元素。

That's value 4.0
You make it to 12.0

这就是价值 4.0
你使它成为 12.0

  • From

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0"
    
  • To

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="12.0"
    
  • <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0"
    
  • <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="12.0"
    

Or If you build with msbuild then just specify VisualStudioVersion property

或者,如果您使用 msbuild 构建,则只需指定 VisualStudioVersion 属性

msbuild /p:VisualStudioVersion=12.0

msbuild /p:VisualStudioVersion=12.0

回答by cat5dev

giammin's solutionis partially incorrect. You SHOULD NOTremove that entire PropertyGroup from your solution. If you do, MSBuild's "DeployTarget=Package"feature will stop working. This feature relies on the "VSToolsPath"being set.

giammin 的解决方案部分不正确。您不应该从您的解决方案中删除整个 PropertyGroup。如果这样做,MSBuild 的“DeployTarget=Package”功能将停止工作。此功能依赖于设置的“VSToolsPath”

<PropertyGroup>
  <!-- VisualStudioVersion is incompatible with later versions of Visual Studio.  Removing. -->
  <!-- <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> -->
  <!-- VSToolsPath is required by MSBuild for features like "DeployTarget=Package" -->
  <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
...
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

回答by pinus.acer

I have Visual Studio 2013 installed. This worked for me:

我安装了 Visual Studio 2013。这对我有用:

<PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' != ''">12.0</VisualStudioVersion>`
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

So I've changed the condition from ==to !=and the value from 10.0to 12.0.

所以我把条件从==to!=和值从10.0to改变了12.0