.net-core – VS 2017如何构建和测试包含.Net Core的混合解决方案

我有一个超过平均水平的复杂(我怀疑)解决方案,在升级到dotnet sdk 1.1和Visual Studio 2017后,我无法从命令行构建和测试.

它一直在VS 2015中使用dotnet sdk 1.0.0-preview2-003131,因此它在我们的构建服务器上的VS 2015和命令行中构建和运行.

但升级到VS 2017后我遇到了一些问题.

概述设置.
我有一个大致如下所示的解决方案(现实生活中的更多项目)

MySolution.sln

> FoundationClasses(x86,.Net Framework 4.5,csproj(legacy)
> BusinessLogic(x86,csproj(legcay)

>参考基础课程

> WebApi(Dotnet Core WebApi,net451,x86(运行时(win8-x86,win10-x86))
> TestProject(Dotnet Core,x86)

>参考文献WebApi

在VS 2015中,这是通过在Git中存储restore.dg和project.fragment.lock.json来实现的,然后我可以运行dotnet restore,然后运行dotnet build和dotnet test.

升级到VS 2017后,当我从Visual Studio构建和运行时,一切正常. (迁移对基础项目的引用有一些麻烦 – 但删除了那些,并在迁移后重新读取,然后一切都很好)

‘dotnet restore mySolution.sln’工作正常.它正确地恢复了WebApi和TestProject的包 – 并且与预览位相反,开箱即用.我不得不摆弄恢复和片段文件.

但是,如果我运行’dotnet build MySolution.sln -f net452 -r win10-x86′,我会收到一堆构建错误.

如果我运行’dotnet msbuild MySolution.sln -f net452 -r win10-x86’就行了.

这是在概述的解决方案中从CLI工具构建的正确方法吗?

因此,对于构建和恢复,我可以从CLI和VS 2017中使用它.并且具有相同的结果.

但是为了测试,一致性停止了.

我可以在Visual Studio Test Explorer中运行测试就好了. Unittests运行良好,绿色.但是,我启动TestServer的集成测试失败,引用不匹配Microsoft.Extensions.DependencyInjection.Abstractions 1.0.0和1.1.0.

因此,测试链中的某些内容需要1.0.0的程序集,但在调试目录中只能找到1.1.0.

这可以通过程序集重定向来解决 – 但是相当多的程序集似乎是错误的/不匹配的.

如果我运行’dotnet test –no-build TestProject / TestProject.csproj’,测试都是绿色的 – 没有问题.

如此突出的问题:

>’dotnet msbuild’是构建混合解决方案的正确方法吗?
>如果我在没有–no-build的情况下运行’dotnet test’,它会在编译时失败 – 与’dotnet build'(不是msbuild)类似的错误
>在我的测试中基于什么不一致 – 如何在VS中执行与CLI相同的操作(最好找出VS 2017中需要1.0.0范围内的程序集的内容)

我希望我能够彻底解释(但很容易理解).

如果需要更多信息来了解情景,请告诉我.

最好的祝福
安德斯

解决方法

好吧,经过一些艰苦的思考/挖掘时间后,我想我找到了合适的解决方案.

将在此发布以供参考.

对dotnet cli问题的交叉引用:https://github.com/dotnet/cli/issues/6032

我有一个现有的遗留解决方案,构建到.Net 4.5,x86,我们称之为oldsolution.sln

我有一个新的解决方案,其中包含来自oldsolution.sln的一些项目,以及一些新的dotnet核心项目,我们称之为mySolution.sln.

新解决方案还需要构建到x86 for .Net 4.5

建造

这里要抓住的关键是Visual Studio 2017使用安装文件夹中的msbuild.exe来构建. dotnet msbuild使用dotnet sdk文件夹中的程序集.这些并不完全相同.

因此要像Visual Studio一样构建,我必须找到正确使用的msbuild可执行文件.

Visual Studio团队已经开发了一个工具(https://www.nuget.org/packages/vswhere),我在构建脚本中使用它.

一切都有效. (建立明智)

下面是我的PSake脚本,用于构建和测试解决方案.

Task BuildApi {
    exec { msbuild ./oldSolution.sln /t:Rebuild /p:Configuration="Release" /p:Platform=x86 /m /verbosity:minimal /nr:false }

    exec { dotnet restore .\mySolution.sln }

    #Find location of VS2017
    $VsPath = .\packages\vswhere.1.0.50\tools\vswhere.exe -latest -property installationPath
    $msBuild17 = "$vsPath\MSBuild\15.0\Bin\MSBuild.exe"

    exec { &$msbuild17 ./mySolution.sln /t:Build /p:Configuration=Release /p:Platform=x86 /m /verbosity:minimal /nr:false }
}

Task TestApi -depends BuildApi{
    if(!(Test-Path TestResults))
    {
    mkdir TestResults
    }
    if(!(Test-Path TestResults/coverage))
    {
    mkdir TestResults/coverage
    }

    $coverage = './packages/OpenCover.4.6.519/tools/OpenCover.Console.exe'
    $target = "`"C:\Program Files (x86)\dotnet\dotnet.exe`""
    $filter = "`"+[WebApi]*`""

    #UnitTests
    $targetargs = "`"test --no-build .\WebApi\test\WebApi.UnitTests\WebApi.UnitTests.csproj -c Release  --logger `"trx;LogFileName=UnitTests.trx`"`""
    $output = 'TestResults/coverage/WebApi.UnitTests.Coverage.xml'
    &$coverage -register:user -oldstyle -target:$target -targetargs:$targetargs -output:$output -filter:$filter

    # IntegrationTests
    $targetargs = "`"test --no-build .\Web\test\WebApi.IntegrationTests\WebApi.IntegrationTests.csproj c Release --logger `"trx;LogFileName=IntegrationTests.trx`"`""
    $output = 'TestResults/coverage/WebApi.IntegrationTests.Coverage.xml'
    &$coverage -register:user -oldstyle -target:$target -targetargs:$targetargs -output:$output -filter:$filter

    #Generate HTML report
    $reportGenerator = "./packages/ReportGenerator.2.4.5.0/tools/ReportGenerator.exe"
    $reportFiles = "TestResults/coverage/WebApi.UnitTests.Coverage.xml;TestResults/coverage/WebApi.IntegrationTests.Coverage.xml"
    $targetDir = "./TestResults/coverage/WebApi"
    &$reportGenerator -reports:$reportFiles -targetdir:$targetDir
}

到现在为止还挺好.

测试

然后我遇到麻烦让OpenCover拿起报道结果.

发现XUnit执行了shadowCopy – 修复此问题是在每个测试项目中放置一个xunit.runner.json(https://xunit.github.io/docs/configuring-with-json.html)

{
  "shadowCopy": false
}

告诉XUnit不要进行卷影复制,因此OpenCover可以找到与被测可执行文件匹配的PDB文件.

最后…

在Visual Studio中运行测试,所有使用Microsoft.AspNetCore.TestHost.TestServer引用某些dotnet核心程序集的测试都失败了,因为“某些东西”引用了v 1.0.0版本的程序集 – 而我的项目引用了v 1.1.x.

我已经通过在app.config文件中为所有失败的程序集进行程序集重定向来修复此问题.没有设法弄清楚使用旧的1.0.0程序集的人/用户 – 但VS 2017构建链中的某些东西似乎也是这样 – 因为这与dotnet测试有关.

但是,这是我的app.config的副本,其中重定向放置在我的集成测试项目中.

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">"
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNetCore.Mvc.Core" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.2.0" newVersion="1.1.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Options" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNetCore.Http.Abstractions" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNetCore.StaticFiles" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.FileProviders.Abstractions" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Primitives" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNetCore.Routing" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNetCore.Routing.Abstractions" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNetCore.Mvc.Formatters.Json" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.2.0" newVersion="1.1.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNetCore.Mvc.ApiExplorer" culture="neutral" publicKeyToken="adb9793829ddae60" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.2.0" newVersion="1.1.2.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Phew ……这是一场激烈的战斗.

但是它的价值.

与传统x86,网络4,5组件相结合的解决方案,在全新的.Net Core Web Api解决方案中运行 – 我很高兴..

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


在开发中,有时候生成验证码的场景目前还是存在的,本篇演示不依赖第三方组件,生成随机验证码图片。 先添加验证码接口 public interface ICaptcha { /// &lt;summary&gt; /// 生成随机验证码 /// &lt;/summary&gt; /// &lt;para
后端技术 .net code 官方文档 https://docs.microsoft.com/zh-cn/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1 上传方式:multipart/form-data 其他参数:Name,Versio
在上一篇文章中,我们比较出单表插入9999行数据,Freesql &gt;&#160;Dapper &gt; EfCore。在本文中,我们来看看级联插入 构建9999行数据 List&lt;Entity&gt; datas = new List&lt;Entity&gt;(); for (int i
需求:导入9999行数据时Dapper, Ef core, Freesql&#160;谁的性能更优,是如何执行的,级联增加谁性能更佳。 确认方法:sql server&#160;的 sys.dm_exec_query_stats SELECT TOP 1000 (select [text] from
资料整理 1.sp-api介绍:https://developer.amazonservices.com/ 2.github文档:https://github.com/amzn/selling-partner-api-docs 3.github代码:https://github.com/amzn/s
最近时间在整SM2算法,在网上看到不少代码,基本都是使用BouncyCastle库,现在这个版本算比较好的拿来分享给大家。 首先引入包&#160;Portable.BouncyCastle 完整代码见Gitee:https://gitee.com/Karl_Albright/CryptoHelper
在上文中,我介绍了事件驱动型架构的一种简单的实现,并演示了一个完整的事件派发、订阅和处理的流程。这种实现太简单了,百十行代码就展示了一个基本工作原理。然而,要将这样的解决方案运用到实际生产环境,还有很长的路要走。今天,我们就研究一下在事件处理器中,对象生命周期的管理问题。事实上,不仅仅是在事件处理器
上文已经介绍了Identity Service的实现过程。今天我们继续,实现一个简单的Weather API和一个基于Ocelot的API网关。 回顾 《Angular SPA基于Ocelot API网关与IdentityServer4的身份认证与授权(一)》 Weather API Weather
最近我为我自己的应用开发框架Apworks设计了一套案例应用程序,并以Apache 2.0开源,开源地址是:https://github.com/daxnet/apworks-examples,目的是为了让大家更为方便地学习和使用.NET Core、最新的前端开发框架Angular,以及Apwork
HAL(Hypertext Application Language,超文本应用语言)是一种RESTful API的数据格式风格,为RESTful API的设计提供了接口规范,同时也降低了客户端与服务端接口的耦合度。很多当今流行的RESTful API开发框架,包括Spring REST,也都默认支
在前面两篇文章中,我详细介绍了基本事件系统的实现,包括事件派发和订阅、通过事件处理器执行上下文来解决对象生命周期问题,以及一个基于RabbitMQ的事件总线的实现。接下来对于事件驱动型架构的讨论,就需要结合一个实际的架构案例来进行分析。在领域驱动设计的讨论范畴,CQRS架构本身就是事件驱动的,因此,
HAL,全称为Hypertext Application Language,它是一种简单的数据格式,它能以一种简单、统一的形式,在API中引入超链接特性,使得API的可发现性(discoverable)更强,并具有自描述的特点。使用了HAL的API会更容易地被第三方开源库所调用,并且使用起来也很方便
何时使用领域驱动设计?其实当你的应用程序架构设计是面向业务的时候,你已经开始使用领域驱动设计了。领域驱动设计既不是架构风格(Architecture Style),也不是架构模式(Architecture Pattern),它也不是一种软件开发方法论,所以,是否应该使用领域驱动设计,以及什么时候使用
《在ASP.NET Core中使用Apworks快速开发数据服务》一文中,我介绍了如何使用Apworks框架的数据服务来快速构建用于查询和管理数据模型的RESTful API,通过该文的介绍,你会看到,使用Apworks框架开发数据服务是何等简单快捷,提供的功能也非常多,比如对Hypermedia的
在上一讲中,我们已经完成了一个完整的案例,在这个案例中,我们可以通过Angular单页面应用(SPA)进行登录,然后通过后端的Ocelot API网关整合IdentityServer4完成身份认证。在本讲中,我们会讨论在当前这种架构的应用程序中,如何完成用户授权。 回顾 《Angular SPA基于
Keycloak是一个功能强大的开源身份和访问管理系统,提供了一整套解决方案,包括用户认证、单点登录(SSO)、身份联合、用户注册、用户管理、角色映射、多因素认证和访问控制等。它广泛应用于企业和云服务,可以简化和统一不同应用程序和服务的安全管理,支持自托管或云部署,适用于需要安全、灵活且易于扩展的用
3月7日,微软发布了Visual Studio 2017 RTM,与之一起发布的还有.NET Core Runtime 1.1.0以及.NET Core SDK 1.0.0,尽管这些并不是最新版,但也已经从preview版本升级到了正式版。所以,在安装Visual Studio 2017时如果启用了
在上文中,我介绍了如何在Ocelot中使用自定义的中间件来修改下游服务的response body。今天,我们再扩展一下设计,让我们自己设计的中间件变得更为通用,使其能够应用在不同的Route上。比如,我们可以设计一个通用的替换response body的中间件,然后将其应用在多个Route上。 O
不少关注我博客的朋友都知道我在2009年左右开发过一个名为Apworks的企业级应用程序开发框架,旨在为分布式企业系统软件开发提供面向领域驱动(DDD)的框架级别的解决方案,并对多种系统架构风格提供支持。这个框架的开发和维护我坚持了很久,一直到2015年,我都一直在不停地重构这个项目。目前这个项目在
好吧,这个题目我也想了很久,不知道如何用最简单的几个字来概括这篇文章,原本打算取名《Angular单页面应用基于Ocelot API网关与IdentityServer4ʺSP.NET Identity实现身份认证与授权》,然而如你所见,这样的名字实在是太长了。所以,我不得不缩写“单页面应用”几个字