4

尝试测试 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 从源启动 Web 部署任务:manifest(C:\Users\Chris\Desktop\SpecsFor-master\SpecsFor.Mvc.Demo\ obj\Test\Package\SpecsFor.Mvc.Demo.SourceManifest.xml)到目的地:包(C:\Users\Chris\Desktop\SpecsFor-master\SpecsFor.Mvc.Demo\obj\Test\Package\SpecsFor.Mvc.演示.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

4 回答 4

4

我出现了这个错误,事实证明我已经在我的解决方案中添加了一个新项目。新项目不包括相同的配置,即解决方案正在运行“测试”,但我的新项目只有调试和发布的默认配置。

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

于 2013-04-06T21:54:45.213 回答
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);
        }
于 2014-05-20T16:08:32.647 回答
0

我在尝试让 SpecsForMvc 在 Bamboo 远程构建代理上工作时遇到了完全相同的问题。Matt Honeycutt 的 回答为我指明了正确的方向。我只需要在运行代理的 VM 上安装MS Web Deploy 3.5即可修复此错误。

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

arni 的 回答帮助我更好地诊断问题,但后来也给我带来了一些问题,当我在尝试从测试的应用程序连接到远程 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);
    }
于 2015-04-10T09:54:39.180 回答
0

看起来错误实际上来自 MSDeploy,SpecsFor.Mvc 通过 MSBuild 在内部使用它来发布您的站点以进行测试。这是直接来自 MSDeploy 的相同错误:Web 部署任务失败。(“Microsoft.Web.Deployment.DeploymentManager”的类型初始化程序引发了异常。)。不幸的是,似乎没有解决方案。

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

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

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

于 2012-12-15T20:25:05.257 回答