18

I just installed Update 2 for Visual Studio 2012, which introduces a new Publish dialog. I'm trying to make it do what it used to do (precompile a website before publishing), and I'm running into the error that it

"Can't find the valid AspnetMergePath"

which is thrown from the file Microsoft.Web.Publishing.AspNetCompileMerge.targets. I've confirmed that the file aspnet_merge.exe exists in multiple places on my computer, but

$(GetAspNetMergePath) 

is evaluating to an empty string for some reason. I must be missing some configuration setting, but I've never messed with those before, so I'm confused as to why this would start suddenly.

Can anyone offer advice on how to resolve this? I've done the standard Google searching on this error and nothing has led me to the right solution.

adsilb
  • 183
  • 1
  • 1
  • 5
  • possible duplicate of ["Can't find the valid AspnetMergePath" on Visual Web Developer Publish?](http://stackoverflow.com/questions/12713714/cant-find-the-valid-aspnetmergepath-on-visual-web-developer-publish) – Kevin Berridge Jun 20 '14 at 20:35

5 Answers5

19

I hit the same problem. Searched through all microsoft related sites, found a lot of complaints and no intention from microsoft to fix it.

Here how I worked it around at my system. Edit the Microsoft.Web.Publishing.AspNetConfigurationMerge.targets file and add the following line. Please make sure that the Microsoft SDK path is the same on your PC, if not then change it:

<TargetFrameworkSDKToolsDirectory>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\</TargetFrameworkSDKToolsDirectory>

Here how it should look like:

  <Target
  Name="GetAspNetMergePath"
  DependsOnTargets="$(GetAspNetMergePathDependsOn)"
  Condition ="'$(GetAspNetMergePath)' != 'false'">
<PropertyGroup>
  <TargetFrameworkSDKToolsDirectory>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\</TargetFrameworkSDKToolsDirectory>
  <AspnetMergeName>aspnet_merge.exe</AspnetMergeName>
  <AspnetMergePath Condition="Exists('$(TargetFrameworkSDKToolsDirectory)$(AspnetMergeName)')">$(TargetFrameworkSDKToolsDirectory)</AspnetMergePath>
</PropertyGroup>
<Error Condition="'$(AspnetMergePath)' == '' Or !Exists($(AspnetMergePath))"
       Text="Can't find the valid AspnetMergePath" />

ialiashkevich
  • 615
  • 7
  • 8
17

I had the same issue today while building using msbuild command line. The fix is to use the msbuild.exe in C:\Program Files (x86)\MSBuild\12.0\Bin
and not from C:\Windows\Microsoft.NET\Framework\v4.0.30319

The issue is caused by the fact that new msbuild is now part of visual studio 2013 and not .Net framework any more.

softveda
  • 10,858
  • 6
  • 42
  • 50
  • Nothing worked but this! Do you know how could I set it permanently for VS 2012? – manishKungwani May 24 '14 at 06:50
  • Yes! Thank you! Another huge point from your link: "The way MSBuild selects Toolset versions for command line builds is now identical to the way Visual Studio builds projects". I could have saved days of tracking down minor nuances between the two if this would have been done from the beginning. – Nelson Rothermel Jul 10 '14 at 04:21
  • Ran into the same problem after we installed VS2013 on our compile machine. We have Jenkins kicking off msbuild compiles and web publish tasks, and they suddenly stopped working. Changing Jenkins to use the VS2013 msbuild fixed things. – Jeff Dege Jul 14 '14 at 18:33
  • 2
    While this may be a great answer, I have no idea how to actually try it - a little more detail may have been nice! Knowing what to do is one thing, knowing how to do it is another entirely – Jon Story Mar 30 '16 at 10:05
  • This issue crops back up when using MSBuild v15 now, using precompile profiles. – Piotr Kula Jun 14 '17 at 11:04
6

Here is a solution that does not require changing the targets file. The workaround from http://connect.microsoft.com/VisualStudio/feedback/details/786492/publish-cant-find-the-valid-aspnetmergepath suggests passing additional properteries to msbuild. I was able to get it to work using this:

msbuild website.publishproj /p:DeployOnBuild=true /p:PublishProfile=Release /p:VisualStudioVersion=12.0 /p:AspnetMergePath="C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\"

The key here is the AspnetMergePath property, which you may need to change if the Windows SDK is installed in a different location. If I include the GetAspNetMergePath property from the workaround it fails, but that may be needed depending on the SDK version.

tspauld
  • 3,512
  • 2
  • 25
  • 22
2

I had the same issue in VS 2012 and all I did was the following:

Click Publish,Under Publish Web go to Settings tab, Uncheck "Precompile during publishing."

tmndungu
  • 320
  • 4
  • 17
0

Another option that worked for me with this same error was to install Visual Studio (in my case express). I built the application one time on the server and then from that point forward it built correctly as part of my continuous integration project.

Bryce
  • 664
  • 6
  • 17