Could not import “$(VSToolsPath)\\…”

2019-09-11 08:14发布

问题:

I am trying to build an existing ASP.NET solution on Mono using xbuild, and among the errors I am getting, this is the first one (trimmed and formatted to fit):

MyProj/OrderQueueJob/OrderQueueJob.csproj: error : 
MyProj/OrderQueueJob/OrderQueueJob.csproj: 
../packages/Microsoft.Web.WebJobs.Publish.1.0.2/tools/webjobs.targets: 
    Project file could not be imported, it was being imported by 
        MyProj/OrderQueueJob/OrderQueueJob.csproj: 
        MyProj/packages/Microsoft.Web.WebJobs.Publish.1.0.2/tools//webjobs.console.targets: 
        Project file could not be imported, it was being imported by 
            MyProj/packages/Microsoft.Web.WebJobs.Publish.1.0.2/tools/webjobs.targets: 
            MyProj/packages/Microsoft.Web.WebJobs.Publish.1.0.2/tools/webjobs.console.targets 
            could not import "$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets"

I am relatively unknowing as to what goes into building .NET projects, but it seems clear that the VSToolsPath seems to be unset, so that the referenced files (targets?) cannot be found. When googling this I only came upon older answers that mentioned that in some (now old) versions of Mono you needed to copy this folder from one location to the next - what seemed to be a simple omission. The weird thing is that I seem to have this folder in the file system, yet it cannot be found!

$ find /usr/local/Cellar/mono -iregex '.*VisualStudio.*Microsoft.WebApplication.targets'
/usr/local/Cellar/mono/4.2.2.30/lib/mono/xbuild/Microsoft/VisualStudio/v10.0/WebApplications/Microsoft.WebApplication.targets
/usr/local/Cellar/mono/4.2.2.30/lib/mono/xbuild/Microsoft/VisualStudio/v11.0/WebApplications/Microsoft.WebApplication.targets
/usr/local/Cellar/mono/4.2.2.30/lib/mono/xbuild/Microsoft/VisualStudio/v9.0/WebApplications/Microsoft.WebApplication.targets

What gives?


Obviously "MyProj" above is a trimmed down version of a longer file path such as /Users/John.Smith/projects/MyProj/.

回答1:

It turned out I have one folder per version of Visual Studio

ls /usr/local/Cellar/mono/4.2.2.30/lib/mono/xbuild/Microsoft/VisualStudio/
v     v10.0 v11.0 v12.0 v14.0 v9.0

As you can see from the output in my question, only some of these actually have the VS Tools. Weird of Xamarin to forget VS2012 and VS2015, but oh, well.

The problem went away when I copied the newest existing version of the folder into the ones missing it:

MONO_VS_DIR=/usr/local/Cellar/mono/4.2.2.30/lib/mono/xbuild/Microsoft/VisualStudio
cp -r $MONO_VS_DIR/v11.0/WebApplications $MONO_VS_DIR/v12.0/
cp -r $MONO_VS_DIR/v11.0/WebApplications $MONO_VS_DIR/v14.0/


标签: asp.net mono