SpecsFor.Mvc Build失败

时间:2012-11-23 23:06:27

标签: msbuild visual-studio-2012 msdeploy

尝试测试SpecsFor.Mvc时,我尝试运行测试时会出现这种奇怪的构建错误。

在我自己的项目和SpecsFor最新源代码中运行,我得到了“构建失败”。来自IISTestRunnerAction类的ApplicationException。以下内容来自日志文件,但超出了我的理解范围。

使用visual studio 2012 pro和IIS Express 8.0

以下内容来自日志文件:

  

使用程序集“C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v11.0 \ Web \ Microsoft.Web.Publishing.Tasks.dll”中的“VSMSDeploy”任务。         任务“VSMSDeploy”           打包/发布任务Microsoft.Web.Publishing.Tasks.VSMSDeploy加载程序集Microsoft.Web.Deployment,Version = 9.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35           打包/发布任务Microsoft.Web.Publishing.Tasks.VSMSDeploy加载程序集Microsoft.Web.Delegation,Version = 7.1.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35           从源:清单(C:\ Users \ Chris \ Desktop \ SpecsFor-master \ SpecsFor.Mvc.Demo \ obj \ Test \ Package \ SpecsFor.Mvc.Demo.SourceManifest.xml)启动Web部署任务到目标:包(C :\用户\克里斯\桌面\ SpecsFor主\ SpecsFor.Mvc.Demo \ OBJ \测试\包\ SpecsFor.Mvc.Demo.zip)。           C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v11.0 \ Web \ Microsoft.Web.Publishing.targets(4007,5):错误:Web部署任务失败。 ('Microsoft.Web.Deployment.DeploymentManager'的类型初始化程序引发了异常。)           包裹失败。         完成执行任务“VSMSDeploy” - 失败。

更新

这是AssemblyStartup

 [SetUpFixture]
public class AssemblyStartup
{
    private SpecsForIntegrationHost _host;

    [SetUp]
    public void SetupTestRun()
    {
        var config = new SpecsForMvcConfig();
        //SpecsFor.Mvc can spin up an instance of IIS Express to host your app 
        //while the specs are executing.  
        config.UseIISExpress()
            //To do that, it needs to know the name of the project to test...
            .With(Project.Named("SpecsForTesting"))
            //And optionally, it can apply Web.config transformations if you want 
            //it to.
            .ApplyWebConfigTransformForConfig("Debug");

        //In order to leverage the strongly-typed helpers in SpecsFor.Mvc,
        //you need to tell it about your routes.  Here we are just calling
        //the infrastructure class from our MVC app that builds the RouteTable.

        config.BuildRoutesUsing(r => SpecsForTesting.RouteConfig.RegisterRoutes(r));

        //SpecsFor.Mvc can use either Internet Explorer or Firefox.  Support
        //for Chrome is planned for a future release.
        config.UseBrowser(BrowserDriver.Chrome);

        //Does your application send E-mails?  Well, SpecsFor.Mvc can intercept
        //those while your specifications are executing, enabling you to write
        //tests against the contents of sent messages.
        config.InterceptEmailMessagesOnPort(13565);

        //The host takes our configuration and performs all the magic.  We
        //need to keep a reference to it so we can shut it down after all
        //the specifications have executed.
        _host = new SpecsForIntegrationHost(config);
        _host.Start();

    }

    //The TearDown method will be called once all the specs have executed.
    //All we need to do is stop the integration host, and it will take
    //care of shutting down the browser, IIS Express, etc. 
    [TearDown]
    public void TearDownTestRun()
    {
        _host.Shutdown();
    }
}

4 个答案:

答案 0 :(得分:4)

我出现了这个错误,结果发现我在我的解决方案中添加了一个新项目。新项目没有包含相同的配置,即解决方案是运行“测试”,但我的新项目只有默认的调试和发布。

进入配置管理器,检查解决方案中的所有项目是否都具有相同的配置。

答案 1 :(得分:3)

如果您要查找构建日志,则默认情况下会将其输出到控制台。以下是捕获控制台输出的方法:

        var stringWriter = new StringWriter();
        try
        {
            // Build log is sent to console, redirect output to StringWriter
            Console.SetOut(stringWriter);
            _host.Start();
        }
        catch (ApplicationException ex)
        {
            throw new Exception("Build failed. Output: " + stringWriter, ex);
        }

答案 2 :(得分:0)

看起来错误实际上来自MSDeploy,SpecsFor.Mvc在内部通过MSBuild发布您的网站进行测试。这是来自MSDeploy的同样错误:Web deployment task failed. (The type initializer for 'Microsoft.Web.Deployment.DeploymentManager' threw an exception.)。不幸的是,似乎没有解决方案。

您可以尝试手动部署网站吗?这个命令行应该可以解决这个问题:

msbuild / p:DeployOnBuild = true; DeployTarget = Package; _PackageTempDir =; AutoParameterizationWebConfigConnectionStrings = false; Platform = AnyCPU

让我知道这是否有效或是否因类似错误而爆炸。

答案 3 :(得分:0)

我试图让SpecsForMvc在Bamboo远程构建代理上工作时遇到了同样的问题。 Matt Honeycutt's answer向我指出了正确的方向。我只需在运行代理的VM上安装MS Web Deploy 3.5来修复此错误。

我还需要在同一个VM上安装IIS Express 8,以允许SpecsForIntegrationHost在其中启动一个站点。

arni's answer帮助我更好地诊断问题,但是当我在尝试从经过测试的应用程序连接到远程SQL Server的权限出现问题时,我也遇到了一些问题。 。这些异常没有被ApplicationException catch块捕获,因为它们是SystemException类。它们由全局异常处理程序处理,绕过了应该关闭集成主机的测试清理的结束。这为在后台运行的每个测试留下了IIS Express实例。 (由于我无法评论arni的回答,我已经在这里添加了修改后的代码)

var stringWriter = new StringWriter();
    try
    {
        // Build log is sent to console, redirect output to StringWriter
        Console.SetOut(stringWriter);
        _host.Start();
    }
    catch (Exception ex)
    {
        _integrationHost.Shutdown();
        throw new Exception("Build failed. Output: " + stringWriter, ex);
    }