简体   繁体   中英

How to find type of project with cake build system?

ITNOA

I use cake build system to automate building my solution and I want to automate testing my project with cake in our CI,

My NUnit projects have many types such as asp.net dot net framework 4.6.1 or dot net core 2.1 or...

my problem is when I want to run our unit test with NUnit3 cake dsl we need to know dll path of each project, so I need to know what is type of each project, because for example for dot net core 2.1 dll is under netcoreapp directory and for another project dll is under somewhere else.

for better demonstration please see below image

我的解决方案的结构

As you can see in Test Solution Folder we have many test projects with different type framework and... (for example one of them is dotnetcore2.1 another one is dot net framework 4.6.1 and etc.)

So my question is how to find type of project?

Is there any solution to NUnit3 found dll by self?

my GitHub discussion about this question

thanks

You should use a project reference for your unit test projects as opposed to an explicit DLL reference.

When you're using.Net Core, Use XUnit testing for allow for near identical process for your test methods.

By using a project reference and having your test projects as part of the same Solution (sln) file, you'll greatly simplify your work.

It looks like what you are trying to do is to get a list of all the assemblies for your unit tests, across any targets that the project might have.

If that's the case, you could use the GetFiles alias to find the assemblies, and then inspect the FullPath of each assembly to check the TFM ...

var files = GetFiles("./**/*.Tests.dll");
foreach(var file in files)
{
    Information("File: {0}", file.FullPath);

    if (file.FullPath.Contains("/net461/")
    {
        // ... Assembly is for .NET 4.6.1
    }
    else if (file.FullPath.Contains("/netcoreapp2.1/")
    {
        // ... Assembly is for .NET Core 2.1
    }
    // etc...
}

You could utilize a globber pattern to find all test projects, don't know you're exakt folder structure but you could do something like below

 Task("Test")
     .Does(() =>
 {
     var settings = new DotNetCoreTestSettings
     {
         Configuration = "Release"
     };

     var projectFiles = GetFiles("./**/Test/UnitTests/*.csproj");
     foreach(var file in projectFiles)
     {
         DotNetCoreTest(file.FullPath, settings);
     }
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM