1

I am trying to use SpecsFor MVC for automated acceptance testing and I have noticed that it is not building / publishing project correctly on Visual Studio 2012 and hence IIS Express is not running, ending in a 'Page cannot be displayed' message throughout the automated acceptance test.

To take you through all my tests to get this working, initially, when trying to run the automated tests, I was getting a 'Build Failed' message when running

_host = new SpecsForIntegrationHost(config);
_host.Start();

. After loading the SpecsFor MVC source code, I have noticed that the error was because the MSBuild.exe process was failing and the output message was being written to Console.Output. After checking the output, I have noticed that the error was that the Microsoft.WebApplication.targets was not found. After some research, I found the below:

  • External VS2013 build error "error MSB4019: The imported project <path> was not found"
    • The one with most votes spoke about removing the <PropertyGroup> node from the .csproj which after removing it, the MSBuild.exe was not exiting with an error code as it only had warnings which still resulted in the project not being built & published correctly. SpecsFor MVC in this case treated this scenario as successful and proceeded with launching IIS Express but since the project was not built successfully, the acceptance tests resulted in another Page Cannot Be Displayed message as IIS Express was not running correctly.
  • After some further research, I found v11.0\WebApplications\Microsoft.WebApplication.targets was not found when file actually references v10 which outlined that VS 2012 has a new different MSBuild.exe file located in C:\Program Files (x86)\MSBuild\12.0\Bin.
    • Now the issue is that within the SpecsFor MVC IISTestRunnerAction.PublishSite() method, the path of the MSBuild.exe is being loaded through System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() which in my case is outputting C:\Windows\Microsoft.NET\Framework64\v4.0.30319\. Changing this manually to C:\Program Files (x86)\MSBuild\12.0\Bin solved the issue and project was built & published successfully.

My final question is: Is there a way where one can change the value of System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() so that I wouldn't need to update the source of the SpecsFor MVC project?

Thanks in advance for any help!

Community
  • 1
  • 1
Mark Cassar
  • 1,842
  • 4
  • 20
  • 27
  • I think overriding how SpecsFor MVC finds MSBuild is the best solution here. I could expose a way to explicitly set the path. Can you open a bug report or feature request on Github so I can remember to look in to this? – Matt Honeycutt Jul 19 '14 at 03:05
  • @MattHoneycutt - Issue reported on https://github.com/MattHoneycutt/SpecsFor/issues/41 - Many thanks for your help! :) – Mark Cassar Jul 21 '14 at 08:25

2 Answers2

1

As of SpecsFor.Mvc 3.2.0-rc01 (still a preview release as of right now), you can configure the path to MSBuild like so:

var config = new SpecsForMvcConfig();
    config.UseIISExpress()
    .With(Project.Named("SpecsFor.Mvc.Demo"))
    .CleanupPublishedFiles()
    //Set the full path to MSBuild.exe here!
    .UseMSBuildExecutableAt(@"C:\Program Files (x86)\MSBuild\12.0\Bin\msbuild.exe")
    .ApplyWebConfigTransformForConfig("Test");
Matt Honeycutt
  • 1,009
  • 11
  • 16
0

To understand how these ".targets" files are organized in Visual Studio is a challenge. I don't know nothing about this SpecsFor MVC works, but if you put the right ".targets" file in it's path, it should work. By your question, I understand that SpecsFor invokes MSBuild internally.

It's a similar problem when you install a new build machine, and a lot of Visual Studio componentes are missing. Not all of them are deployed with the framework. Some comes with Visual Studio separated installers other with specific componentes.

I didn't find an specific installer that deploys this needed file. I just found the MSBuild 2012 installer (http://www.microsoft.com/en-us/download/details.aspx?id=40760), and I don't know if it deploys the previous version .targets.

And also you can try the ASP.NET MVC installer for your specific version.

Another approach is try to find a parameter in SpecsFor to see which version of MSBuild it is invoking. Probably if it uses the version in Program Files\v12, it should work.

Eric Lemes
  • 561
  • 3
  • 10
  • Yes, if it would use the new VS 2012 MSBuild found in `C:\Program Files (x86)\MSBuild\12.0\Bin`, it works fine. But it is reading the path of the MSBuild through the `System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()` which is in my case returning `C:\Windows\Microsoft.NET\Framework64\v4.0.30319\` which when executed outputs the `.targets` error – Mark Cassar Jul 18 '14 at 12:08
  • Sorry, I didn't answer your question. I think there are two approaches: 1) Find and install the right package that deploys the needed .targets file (I bet in some ASP.NET MVC package) or 2) Change SpecFlow to accept a different MSBuild Path. Since it's an open source project, what about a Pull Request? – Eric Lemes Jul 18 '14 at 12:16
  • I would say 2. would make more sense if there's no alternative to change the resulting output of `System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()`. I have contacted the creator of the project for feedback and then will look into a Pull Request – Mark Cassar Jul 18 '14 at 12:21
  • Yeah. It's a good alternative. This kind of collaboration is allways interesting. I think there's no free lunch in your problem. I can't see a different approach. – Eric Lemes Jul 18 '14 at 12:24