简体   繁体   English

如何使用VSTS构建包含.NET Standard项目和.NET 4.7项目的.NET解决方案?

[英]How to use VSTS to build a .NET solution that contains a .NET Standard project and a .NET 4.7 project?

I have a .NET solution which has 2x projects: 我有一个.NET解决方案,其中有2个项目:

  • .NET Standard 1.6 .NET标准1.6
  • .NET 4.7 xUnit project .NET 4.7 xUnit项目

Unfortunately, I'm using a package in the xUnit project that doesn't work in a .NET Core xUnit project, which is why I'm using a .NET 4.7 project for unit testing. 不幸的是,我在xUnit项目中使用的软件包在.NET Core xUnit项目中不起作用,这就是为什么我将.NET 4.7项目用于单元测试的原因。

So, i'm not sure how to do this with Visual Studio Team Services. 因此,我不确定如何使用Visual Studio Team Services执行此操作。

Previously, I've just had a .NET Standard Project and a .NET Core xUnit project and have the following: 以前,我刚刚有一个.NET Standard项目和.NET Core xUnit项目,并且具有以下内容:

  • Get Sources (GIT) 取得资源(GIT)
  • Restore (.NET Core) 还原(.NET Core)
  • Build (.NET Core) 生成(.NET Core)
  • Pack (.NET Core) Pack(.NET Core)
  • NuGet Push NuGet推送

So - how do I : 所以-我该如何:

  • restore + build a .NET Core project 恢复+构建.NET Core项目
  • and then the .NET 4.7 project 然后是.NET 4.7项目
  • and then run the xunit tests for the .NET 4.7 project 然后为.NET 4.7项目运行xunit测试
  • and finally pack/nuget push the .NET Standard 1.6 project. 最后打包/推送推送.NET Standard 1.6项目。

please? 请?


EDIT: 编辑:

here's what it looks like on my LOCALHOST machine when i try and do a normal dotnet restore 这是我尝试进行正常的dotnet restore时在LOCALHOST计算机上的外观

Notice: - Hornet.Services.csproj is restored. 注意: Hornet.Services.csproj已还原。 - Hornet.Services.Tests.csproj is not located or restored. - Hornet.Services.Tests.csproj或恢复Hornet.Services.Tests.csproj - Both projects are in my sln, as shown above with the screen shot above. -这两个项目都在我的sln中,如上图所示,上面是屏幕截图。

c:\Projects\Personal\Hornet\Hornet.Services>dotnet restore
  Restoring packages for c:\Projects\Personal\Hornet\Hornet.Services\src\Hornet.Services\Hornet.Services.csproj...
  Generating MSBuild file c:\Projects\Personal\Hornet\Hornet.Services\src\Hornet.Services\obj\Hornet.Services.csproj.nuget.g.props.
  Writing lock file to disk. Path: c:\Projects\Personal\Hornet\Hornet.Services\src\Hornet.Services\obj\project.assets.json
  Restore completed in 1.42 sec for c:\Projects\Personal\Hornet\Hornet.Services\src\Hornet.Services\Hornet.Services.csproj.

  NuGet Config files used:
      c:\Projects\Personal\Hornet\Hornet.Services\NuGet.Config
      C:\Users\Pure Krome\AppData\Roaming\NuGet\NuGet.Config
      C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

  Feeds used:
      https://api.nuget.org/v3/index.json
      https://purekrome.pkgs.visualstudio.com/_packaging/Hornet-Dev/nuget/v3/index.json

c:\Projects\Personal\Hornet\Hornet.Services>

There's many things going on here: 这里发生了很多事情:

  1. There are now many ways to create a .NET Framework xUnit test project - classic .NET projects or "SDK-based" projects. 现在,有许多方法可以创建.NET Framework xUnit测试项目-经典.NET项目或“基于SDK”的项目。 Currently, only .NET Core and .NET Standard project templates (as well as the "ASP.NET Core (.NET Framework" one) create SDK-based projects, but the TargetFramework property in the csproj file can easily be changed to net47 from eg netcoreapp1.1 . 目前,只有.NET的核心和.NET标准项目模板(还有“ASP.NET核心(.NET框架”一节)创建基于SDK的项目,但TargetFramework中的csproj文件属性可以轻易地改变net47从例如netcoreapp1.1

  2. By default, classic projects use a packages.config file for NuGet references. 默认情况下,经典的项目使用packages.config为的NuGet引用文件。 Only the nuget.exe command line can restore these types of projects. 只有nuget.exe命令行可以还原这些类型的项目。 The msbuild-integrated way of referencing NuGet packages using the PackageReference items can be used directly via MSBuild using msbuild /t:Restore which is what dotnet restore does. 可以使用msbuild /t:Restore通过MSBuild直接使用msbuild /t:Restore集成的使用PackageReference项引用NuGet包的方式,这是dotnet restore作用。 This means that dotnet restore is unable to restore packages.config based projects. 这意味着dotnet restore无法恢复基于packages.config的项目。 Note that even classic .NET Framework projects (non-SDK-based) can use the PackageReference style in VS 2017 versions >= 15.2. 请注意,即使是经典的.NET Framework项目(基于非SDK的项目)也可以在VS 2017版本> = 15.2中使用PackageReference样式。

  3. The support for dotnet test is provided by the Microsoft.NET.Test.Sdk NuGet package and is meant to be used for SDK-based projects. Microsoft.NET.Test.Sdk NuGet软件包提供了对dotnet test的支持,该支持旨在用于基于SDK的项目。 This package contains the necessary configuration and msbuild targets to allow running tests via msbuild /t:VSTest - which is what dotnet test calls. 该软件包包含必要的配置和msbuild目标,以允许通过msbuild /t:VSTest运行测试-这是dotnet test调用的。 Classic unit test projects do not contain or reference this logic and rely on a test runner to detect and run tests (eg the classic Unit Test VSTS task that uses a visual studio installation). 经典单元测试项目不包含或引用此逻辑,而是依靠测试运行程序来检测和运行测试(例如,使用Visual Studio安装的经典单元测试VSTS任务)。

  4. Even though dotnet build should be able to build many classic .NET Framework projects, many features may not work since the underlying build tasks are meant to be run on .NET Framework and may behave differently or are completely unsupported on the .NET Core version of MSBuild - eg resx files cannot use file references, assembly signing is limited , COM references don't work etc. As a precaution or fix for these situations, use msbuild instead of the dotnet based tools. 即使dotnet build应该能够构建许多经典的.NET Framework项目,但许多功能可能也不起作用,因为基本的构建任务是要在.NET Framework上运行的,并且其行为可能有所不同,或者在.NET Core版本上完全不受支持。 MSBuild-例如, resx文件不能使用文件引用,程序集签名受到限制,COM引用不起作用等。为预防或解决这些情况,请使用msbuild而不是基于dotnet的工具。 ( msbuild /t:Restore , msbuild /t:Publish /p:Configuration=Release , msbuild /t:VSTest etc.) msbuild /t:Restoremsbuild /t:Publish /p:Configuration=Releasemsbuild /t:VSTest等)

My suggestion: Create the test project as .NET Core xUnit project and change the TargetFramework in the csproj to net47 so that you can use all of the dotnet tooling features. 我的建议:将测试项目创建为.NET Core xUnit项目,并将csproj中的TargetFramework更改为net47以便可以使用所有dotnet工具功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET 4.7 xunit测试项目在引用.NET Standard 1.6项目时无法构建 - .NET 4.7 xunit test project fails to build when referencing a .NET Standard 1.6 project 如何在 .NET 2 项目中使用 .NET 4.7 程序集? - How can I use .NET 4.7 assembly in .NET 2 project? 如何在VSTS中构建.net核心和完整的.net项目 - How to build .net core and full .net project in VSTS .NET Framework 4.7项目中的.NET标准类库 - .NET Standard Class Library in .NET Framework 4.7 project 将 .net 4.6.1 项目更改为 .net 4.7 失败 - change a .net 4.6.1 project to .net 4.7 failed .NET Standard项目生成失败,并显示无用的消息 - .NET Standard project build fails with unhelpful message 如何在VSTS(CI)中为.NET标准库(2.0)项目启用代码覆盖率 - How do I enable Code Coverage for .NET Standard Library (2.0) project in VSTS (CI) 无法在.NET Framework 4.7中创建项目 - Can't create a project in .NET Framework 4.7 如何在.NET Framework,.NET Standard和.NET Core项目之间使用相同的配置? - How to use use same configuration between .NET Framework, .NET Standard, and .NET Core project? 在.Net Framework 4.7应用程序中使用.Net标准库 - Use .Net Standard library in .Net Framework 4.7 application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM