Tuesday, 1 September 2015

MSBuild / Visual Studio wpp.targets was not found

I saw many projects which always have built.bat which allow to build project without opening visual studio and it was mistery for me until now. In my team we have designer who can but dont need to open Visual Studio but needs to build project locally. So i have created simple bat file.
But it was not working even when we open VS on that machine it shows exceptions.


Microsoft Visual Studio


The imported project "PATH\*.wpp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets




After some googling i found post about how to solve this


But then it breaks publish functionality. So i solve this issue buy adding parameter to ms build and tuning Web csproj by adding condition. If parameter  SkipWebPublish. is passed to msbuild then VSToolsPath will skip initialization


    <VSToolsPath Condition="$(SkipWebPublish) == '' Or $(SkipWebPublish) == '*Undefined*'">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>


Then build.bat command will have to pass this parameter

@echo off
reg.exe query "HKLM\SOFTWARE\Wow6432Node\Microsoft\MSBuild\ToolsVersions\12.0" /v MSBuildToolsPath > nul 2>&1
if ERRORLEVEL 1 goto MissingMSBuildRegistry

for /f "skip=2 tokens=2,*" %%A in ('reg.exe query "HKLM\SOFTWARE\Wow6432Node\Microsoft\MSBuild\ToolsVersions\12.0" /v MSBuildToolsPath') do SET MSBUILDDIR=%%B

IF NOT EXIST "%MSBUILDDIR%msbuild.exe" goto MissingMSBuildExe

"%MSBUILDDIR%msbuild.exe" /version

"%MSBUILDDIR%msbuild.exe" Source/SolutionName.sln /t:rebuild /p:configuration=Debug /p:Platform="Any CPU" /p:VisualStudioVersion=12.0 /p:SkipWebPublish=true

Volodymyr Bilyachat Web Developer