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

24

215

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.

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.

$(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.

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.

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

Thoughts?

Accentuate answered 31/10, 2013 at 23:19 Comment(2)
Similar question here #17434404Proximal
In my case, I had to specify the correct VisualStudioVersion in the build event that was building with the WebPublish target.Libration
A
263

I had the same issue and find an easier solution

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

<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 out you 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.

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

msbuild myproject.csproj /p:VisualStudioVersion=12.0

or edit your build definition:

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

Achilles answered 20/11, 2013 at 11:54 Comment(11)
I got the error using msbuild from command prompt. Removing this part from the project file sovled the problem.Pentacle
I was using VS2013 with TFS2012 and this solution worked for me.Blacksmith
I used this answer and it worked only if I ensured that my *proj file began with <Project ToolsVersion="12" Before I had <Project ToolsVersion="4" and every time I opened the project in VS it added the two nodes again (i.e. it re-migrated the project to latest version).Greyhen
When I did this, my wpp.targets files in my solution didn't work anymore. I only have this problem when I install only VS2013 on a pc and not a server and then use this as a build machine. My own pc has a clean install and I only have installed VS2010 and VS2013 and everything works fine with this piece of config. Even if you choose new project in VS2013 and look at the project file created, the piece of config is also there. So it must be something else...Timeserver
@RalphJansen yes this is if you have only vs2013Achilles
@giammin, I already found the solution. DON'T remove the section from your project file. Set the right 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 "/p:VisualStudioVersion=12.0". Of course without the quotes. If you have more parameters, separate them with a space and not a comma. The config that you suggested to remove is used by other parts of visual studio in your build proces...Timeserver
@RalphJansen this solution works for you because you have vs2010Achilles
This worked for me and got me building again with only VS2013 installedAlbertinealbertite
Removing that line seems to break Web DeployTimetable
I had same issue was solved by using the /p:VisualStudioVersion=12.0 property as recommended above. ThanksTimekeeper
upvote for /p:VisualStudioVersion=12.0, it solved my problem in integration with JenkinsForepeak
T
72

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

/p:VisualStudioVersion=12.0 

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

Timeserver answered 21/3, 2014 at 10:51 Comment(4)
We just completed an upgrade from TFS 2005 to TFS 2013 and this was our last hurdle. This definitely worked for us and saved me from pulling my hair out. Thanks so much! +1.Reiterant
This article by Sayed Ibrahim Hashimi describes the problem in Visual Studio 2010/2012. A command line build uses the sln file format version -1 as the VisualStudioVersion. You can override this value from the command line as Ralph describes, or as a property of the MSBuild task from a build script. I had the same problem with Visual Studio 2013, and overriding VisualStudioVersion resolved the issue.Xiomaraxiong
This worked for us as well. We also considered modifying the build template itself, described here, which might be a better option if you have dozens of build definitions.Doloroso
this worked for me. I deleted in the csproj files any reference to visualstudioversion and then added that msbuild argumentEtheridge
B
51

This is closely related but may or may not fix OPs specific issue. In my case I was trying to automate the deployment of an Azure site using VS2013. Building and deploying via VS works, however, using MSBuild showed a similar error around the "targets". Turns out MSBuild is different under VS2013, and is now part of VS and not the .Net Framework (see http://timrayburn.net/blog/visual-studio-2013-and-msbuild/). Basically, use the correct version of MSBuild:

OLD, VS2012

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe

NEW, VS2013

C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe

Newer, VS2015

C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe

Newer still, VS2017 (not fully testing but discovered - they've moved things around a bit)

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe
Ballesteros answered 18/10, 2014 at 19:10 Comment(1)
This fixed it for me. Also, similar answer for a similar question here: https://mcmap.net/q/73123/-v11-0-webapplications-microsoft-webapplication-targets-was-not-found-when-file-actually-references-v10Proximal
A
23

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

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.

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

Hopefully, this post helps someone else.

Accentuate answered 31/10, 2013 at 23:27 Comment(1)
Thank you SO much, this solved my issue when building nodeJS node-gyp the Cpp default.props was not found! +1Hypothyroidism
J
21

giammin's solution is partially incorrect. You SHOULD NOT remove 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.

<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)' != ''" />
Jez answered 3/6, 2014 at 17:26 Comment(0)
A
10

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

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

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.

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

Armorial answered 29/1, 2014 at 1:22 Comment(3)
This is probably a common scenario when running a build server (such as CruiseControl or TeamCity), where the service runs under a particular service account which may not even have interactive desktop permissions. This tip solved the issue for me (VS 2013 installed on a clean install of Server 2008 R2, with CruiseControl.NET)Marleah
Where can I see my "VisualStudioVersion" ?Canticle
@Canticle view the environment variables by selecting System from the Control Panel, then select Advanced system settings, and finally click Environment VariablesArmorial
W
6

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

Windowsill answered 22/1, 2014 at 20:59 Comment(1)
This worked for me and was preferable to modifying the project file.Fatty
L
4

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

That's value 4.0
You make it to 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"
    

Or If you build with msbuild then just specify VisualStudioVersion property

msbuild /p:VisualStudioVersion=12.0

Lonni answered 28/5, 2014 at 9:18 Comment(1)
The ToolsVersion must not be the only variable to fix this error message because I saw project with ToolsVersion that could not build correctly.Pilothouse
A
2

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.

Accentuate answered 20/11, 2013 at 13:6 Comment(0)
H
2

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

<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.0 to 12.0.

Hydrocephalus answered 10/7, 2014 at 11:54 Comment(0)
A
2

I had similar issue. All proposed solutions are just work around for this issue but are not solving source of error. @giammin solution should not be applied if you are using tfs build server as it is just crashed publish functionality. @cat5dev solution - solves issue but do not solve source of it.

I`m almost sure that you are using build process template for VS2012 like ReleaseDefaultTemplate.11.1.xaml or DefaultTemplate.11.1.xaml these build templates have been made for VS2012 and $(VisualStudioVersion) set to 11.0

You should use build process template for VS2013 ReleaseTfvcTemplate.12.xaml or TfvcTemplate.12.xaml which has $(VisualStudioVersion) set to 12.0

This works without any changes in project file.

Anhydrous answered 5/9, 2014 at 14:43 Comment(0)
S
2

I also had the same error .. I did this to fix it

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" />

change to

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

and it's done.

Seavey answered 17/5, 2016 at 7:59 Comment(0)
S
2

In my case i just comment below line by opening .csproj file and did the trick

.<!-- <Import Project="..\PRPJECTNAME.targets" /> -->

My problem may be different but i am dragged here, but this may help someone.

I picked a single web project from my solution and try to open it as a stand alone project which was making issue, after above heck am able to solve issue.

Shoop answered 30/3, 2017 at 14:10 Comment(1)
You will have a risk that your solution will not be published with latest changes inside.Koran
E
2

Use the correct version of MSBuild. Set Environment Variable to:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin

This will also work for VS 2019 projects

Previously we were setting it to C:\Windows\Microsoft.NET\Framework\v4.0.30319

Etesian answered 4/12, 2019 at 15:55 Comment(2)
I used "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" instead of "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" and its workedSneer
Yeah, I'm using an SSDT project (.sqlproj), with VisualStudioVersion = 14.0 in the project file. I installed core 3.1, which set my env vars for the targets to God only knows where. Using the msbuild in the folder you suggested worked like a charm!Edmead
E
1

In my case dev environment is VS2013 and I am using TFS 2010. Build was targeted for .NET 4.5.1. I was setting up auto build for CI. whenever I tried workarounds mentioned above - like removing properties group completely or replacing some lines etc.my build used to happen in TFS but my publish to azure used to fail with 'MSDeploy' or at times some different error. I was not able to achieve both simultaneously.

So finally I had to pass MSBuild argument to resolve the issue.

Goto Edit build definition > Process > 3. Advanced > MSBuild Arguments (set to) /p:VisualStudioVersion=12.0

It worked for me.

Eutectoid answered 18/9, 2014 at 11:15 Comment(0)
M
1

You should copy folder WebApplications from C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\ to C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\

Mushroom answered 3/10, 2014 at 5:39 Comment(1)
Or copy just the Microsoft.WebApplication.targets file from a location where Visual Studio 2013 is installed.Horacehoracio
V
0

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.

Vallation answered 14/2, 2014 at 8:34 Comment(0)
G
0

Only one thing needs to be done to solve the problem: upgrade TeamCity to version 8.1.x or higher because support for Visual Studio 2012/2013 and MSBuild Tools 2013 was only introduced in TeamCity 8.1. Once you've upgraded your TeamCity modify MSBuild Tools Version setting in your build step accordingly ans the problem will disappear. For more info read here: http://blog.turlov.com/2014/07/upgrade-teamcity-to-enable-support-for.html

Gamali answered 24/7, 2014 at 15:54 Comment(0)
L
0

Me - nothing was helping in changing the v11.0 value of VisualStudioVersion variable to v10.0. Changing variable in .csproj file didn't. Setting it through command promt didn't. Etc...

Ended up copying my local folder of that specific version (v11.0) to my build server.

Leonardaleonardi answered 21/8, 2014 at 11:36 Comment(0)
B
0

I had tried all of the above solutions and still no luck. I had heard people installing visual studio on their build servers to fix it, but I only had 5gb of free spaces so I just copied C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio to my build server and called it a day. Started working after that, using team city 9.x and visual studio 2013.

Beggar answered 4/2, 2016 at 7:28 Comment(0)
S
0

Based on TFS 2015 Build Server

If you counter this error ... Error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.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.

Open the .csproj file of the project named in the error message and comment out the section below

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

Sailcloth answered 10/3, 2017 at 17:1 Comment(1)
You will have a risk that your solution will not be published with latest changes inside.Koran
R
0

I got this error when I install some VS components. Unfortunately none of these answers didn't help me. I use TFS for command development and I have no permissions to edit build definition. I solved this problem by deleting environment variables which called VS110COMNTOOLS and VS120COMNTOOLS. I think it was installed with my VS components.

Raglan answered 27/3, 2017 at 16:31 Comment(0)
C
0

I found I was missing the WebApplications folder on my local PC, did not install with Visual Studio 2017 like it had when I was using 2012.

Championship answered 28/7, 2017 at 14:56 Comment(0)
B
0

In my case I was using the wrong version of MSBuild.exe.

The version you need to use depends on what version of Visual Studio you used to create your project. In my case I needed 14.0 (having used Visual Studio 2015).

This was found at:

C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe

You can look under:

C:\Program Files (x86)\MSBuild

To find other versions.

Breannabreanne answered 3/10, 2018 at 15:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.