Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuildWorkspace.OpenSolutionAsync looking for targets in Visual Studio/v14.0

Tags:

roslyn

msbuild

I have a VS 2013 console application that loads any solution(.sln) file - compiles all projects within it using Roslyn and extracts API usage information from the compilation model.

I am now facing this peculiar issue - When I run the application from within Visual Studio 2013 (using Ctrl-F5 or F5) everything works fine. I am able to compile stuff and extract all information. However when I open a command line (cmd) and try to run this Console app from I get the following error:

Unhandled Exception: System.AggregateException: One or more errors occurred. ---> Microsoft.Build.Exceptions.InvalidProjectFileException: 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 <Impor
When I run 

Note the v14.0 there. Why does MSBuildWorkspace try to look into v14.0 directory for required target files ? Is it because I installed the MSBuild tools for CTP and the default path while I run stuff from a simple command line has changed ?

--Edit-- Here is the import

<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

However I doubt it is to do with the Import statement as such. If I run the console app .exe from the "Developer Command Prompt for Visual Studio 2013" everything works fine again.

like image 434
shekhar Avatar asked Dec 19 '14 13:12

shekhar


2 Answers

You can make your Web Application projects self-contained and not require Visual Studio 2015 to compile by adding NuGet reference to MSBuild.Microsoft.VisualStudio.Web.targets.

like image 51
Slawomir Brzezinski Avatar answered Nov 18 '22 23:11

Slawomir Brzezinski


I had this problem on my build server. When I targeted /tv:14.0 (Tool Version 14.0 which is the Roslyn Build engine)

I resolved it by going out to C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio then creating folders like v14.0\WebApplications

I then went out to my system with Microsoft.WebApplication.targets (because this is put out there by Visual Studio 2015) and copied that file out to the build servers new folder.

like image 39
DoomVroom Avatar answered Nov 18 '22 23:11

DoomVroom