[英]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个项目:
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项目,并且具有以下内容:
So - how do I : 所以-我该如何:
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: 这里发生了很多事情:
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
。
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样式。
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任务)。
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:Restore
, msbuild /t:Publish /p:Configuration=Release
, msbuild /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.