无法在VSTS中的托管构建代理上运行ASP.NET Core应用程序的自动化测试

时间:2016-09-17 21:45:04

标签: asp.net-core azure-devops

我有一个使用.NET Core 1.0.1构建的应用程序 - VS 2015 Tooling Preview 2(使用Visual Studio Update 3)。我也有一个测试项目,使用我根据本指南构建的MS测试:https://docs.microsoft.com/en-us/dotnet/articles/core/testing/unit-testing-with-dotnet-test

该解决方案由两个项目组成,一个是ASP.NET WebApi控制器,另一个是关联的测试项目。

我的目标是在Visual Studio Team Services(Visual Studio Online)中为Azure设置自动构建,测试和部署。

我已根据本指南设置了自动构建:https://www.visualstudio.com/en-gb/docs/build/get-started/dot-net。该指南提供了两种选择,我尝试过两种方法:

  • 使用Visual Studio Solution步骤构建.sln
  • 或命令行步骤编译各个项目(在每个项目根目录中运行dotnet build)。

在将global.json sdk版本从1.0.0-preview2-003131更改为1.0.0-preview2-003121后,构建解决方案步骤成功通过。但是,为每个项目运行单个dotnet build也可以使用003131。

为了运行测试,我有一个调用dotnet test的命令行步骤。这个没有通过,请参阅下面的错误消息:

2016-09-16T18:46:40.2293724Z The specified framework 'Microsoft.NETCore.App', version '1.0.1' was not found.
2016-09-16T18:46:40.2293724Z   - Check application dependencies and target a framework version installed at:
2016-09-16T18:46:40.2293724Z       C:\Program Files\dotnet\shared\Microsoft.NETCore.App
2016-09-16T18:46:40.2293724Z   - The following versions are installed:
2016-09-16T18:46:40.2293724Z       1.0.0
2016-09-16T18:46:40.2293724Z       1.0.0-rc2-3002702
2016-09-16T18:46:40.2293724Z   - Alternatively, install the framework version '1.0.1'.
2016-09-16T18:46:40.2303741Z SUMMARY: Total: 1 targets, Passed: 0, Failed: 1.
2016-09-16T18:46:40.2593745Z ##[error]Process completed with exit code -2147450749.

看起来我在VSTS中的托管代理上没有正确版本的ASP.NET SDK。但是,我确实有几个问题:

  • 为什么构建成功但运行测试失败?由于缺少框架版本,编译时编译是否会失败?似乎只在运行时检测到问题,在调用测试时,为什么?
  • 为什么在使用1.0.0-preview2-003131时单个项目构建通过但是解决方案构建没有?
  • 根据https://www.visualstudio.com/en-us/docs/build/admin/agents/hosted-pool#software,托管代理显然拥有" .NET Core 1.0 with Preview 2 Tooling"。我很高兴降级我的代码以使用它,但我在哪里可以找到它?我找到的所有下载源(官方http://dot.net页面,MSDN链接)都是1.0.1和1.0预览2无处可寻。

谢谢。

我在下面列出了来自两个项目的global.json和project.json文件,以防它们可以提供帮助。

global.json

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-003131"
  }
}

Project.json用于WebApi项目

{
    "dependencies": {
        "Microsoft.NETCore.App": {
            "version": "1.0.1",
            "type": "platform"
        },
        "Microsoft.AspNetCore.Mvc": "1.0.1",
        "Microsoft.AspNetCore.Routing": "1.0.1",
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
        "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
        "Microsoft.Extensions.Configuration.Json": "1.0.0",
        "Microsoft.Extensions.Logging": "1.0.0",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.Extensions.Logging.Debug": "1.0.0",
        "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
        "Swashbuckle": "6.0.0-beta901",
        "Swashbuckle.SwaggerGen": "6.0.0-beta901",
        "Swashbuckle.SwaggerUi": "6.0.0-beta901"
    },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

    "buildOptions": {
        "emitEntryPoint": true,
        "preserveCompilationContext": true,
        "xmlDoc": true,
        "nowarn": [ "1591" ]
    },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
来自测试项目的

project.json

{
    "version": "1.0.0-*",
    "testRunner": "mstest",

    "dependencies": {
        "Microsoft.NETCore.App": {
            "type": "platform",
            "version": "1.0.1"
        },
        "dotnet-test-mstest": "1.1.1-preview",
        "MSTest.TestFramework": "1.0.3-preview",
        "WebApiCoreMock": {
            "target": "project"
        }
    },

    "frameworks": {
        "netcoreapp1.0": {
            "imports": [
                "dotnet5.6",
                "portable-net45+win8"
            ]
        }
    }
}

1 个答案:

答案 0 :(得分:0)

看起来我能够回答我自己的问题,我已经取代了:

"dependencies": {
    "Microsoft.NETCore.App": {
        "version": "1.0.1",
        "type": "platform"
    },

"dependencies": {
    "Microsoft.NETCore.App": {
        "version": "1.0.0-rc2-3002702",
        "type": "platform"
    },

现在dotnet test步过了。

由于我仍不确定解决方案构建步骤与单个dotnet build命令实际发生了什么,我将打开问题。