Import Tag MSBuild Errors

Creating a SharePoint package is easy enough with Visual Studio but each time you restart it, the package location used previously is replaced with the default location of the current user’s Documents folder.

To save a few seconds from my life I decided to write a PowerShell script to build and package the solution, meaning I no longer have to specify the publish location whenever Visual Studio is restarted.

I’m using Visual Studio 2013 and SharePoint 2013

& "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" "C:\Projects\TestProject\TestSolution.csproj" /t:rebuild;package
 
Write-Host "Copying TestSolution.wsp to Packages folder" -NoNewLine
Copy-Item -Confirm:$false "C:\Projects\TestProject\bin\Debug\TestSolution.wsp" C:\Packages\
Write-Host " - done."

The script shown has been simplified for this post and is easy enough to parametrise to allow you to specify different SharePoint projects to package.

Anyway, back to the main reason for this post.

After doing the above and running the script the following error was generated:

C:\Projects\TestProject\TestSolution.csproj(88,3): error MSB4019: The imported project “C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\SharePointTools\Microsoft.VisualStudio.SharePoint.targets” was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

The thing that immediately stood out for me was the mention of v10 of Visual Studio. I’m using VS 2013, so this should be v12.

Both Visual Studio 2012 and 2013 allow opening and building of 2010 solutions. To achieve this VS injects the current version when building from the IDE but when running from the command line, msbuild does not know which version to use so is defaulting to v10. Which is exactly what would happen when trying to build the project from VS 2010, it would simply default to v10 as no version number injection would occur in this version of the IDE.

The easy fix for this is to add an additional argument to the msbuild command:

& "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" "C:\Projects\TestProject\TestSolution.csproj" /t:rebuild;package /p:VisualStudioVersion=12.0
 
Write-Host "Copying TestSolution.wsp to Packages folder" -NoNewLine
Copy-Item -Confirm:$false "C:\Projects\TestProject\bin\Debug\TestSolution.wsp" C:\Packages\
Write-Host " - done."

Here I’m setting the argument VisualStudioVersion to 12. For Visual Studio 2012 this would be set to 11.

This entry was posted in Visual Studio and tagged , . Bookmark the permalink.
0 0 votes
Article Rating
Subscribe
Notify of
guest

Solve the maths problem shown below before posting: *

1 Comment
Inline Feedbacks
View all comments
Edison

Thanks for your quick fix. I got stuck with this some days ago, it worked like a charm. 🙂