gpt4 book ai didi

.net - 使用混合 .NET Core 和框架解决方案的 Azure Devops 中的 Cake 构建脚本失败

转载 作者:行者123 更新时间:2023-12-02 00:54:31 26 4
gpt4 key购买 nike

我的 .NET 服务器项目有一个 Cake 构建脚本,需要在我们的新 Azure DevOps 上构建。管道。该脚本在本地运行,但不适用于 Azure DevOps。这可能是因为我有一个 unit tests。项目 ( xUnit ) 基于 .NET Core 2.1 构建,而解决方案中的所有其他项目都是 .NET Framework 4.6.1(我们刚刚添加到 xUnit 项目中,我唯一的选择是将其作为 .NET Core 项目添加) .

我编写了可在本地运行的 Cake 脚本。它看起来像这样:

// Always lock down versions of tools so that we can ensure
// a tool works before upgrading instead of auto-upgrading.
#tool "nuget:?package=xunit.runner.console&version=2.4.1"
#tool "nuget:?package=ReportUnit&version=1.2.1"

var target = Argument("target", "Build");
var configuration = Argument("configuration", "Dev");
var solution = @".\MyCompany.MyProduct.IntegrationLayer.sln";
var report = Directory(@".\reports");
var xunitReport = report + Directory("xunit");

Task("Clean")
.Does(() =>
{
Information("Cleaning out directories {0} for {1}...", configuration, solution);
CleanDirectories("./**/bin/" + configuration);
CleanDirectories("./**/obj/" + configuration);
});

Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
// This can restore both .NET Core and Framework NuGet packages.
Information("Restoring Nuget packages for {0}...", solution);
DotNetCoreRestore();
});

Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
// If we change all the projects and solution to .NET Core, then
// we will need to change this build call to DotNetCoreBuild().
//
// Because we have a mixed solution (unit tests are .NET Core and all
// other projects are .NET Framework), we need to still use MSBuild.
Information("Building solution {0} using the {1} configuration...", solution, configuration);
MSBuild(solution, new MSBuildSettings {
Configuration = configuration
});
});

Task("UnitTests")
.IsDependentOn("Build")
.Does(() =>
{
Information("Unit testing solution {0} using the {1} configuration...", solution, configuration);
var projects = GetFiles("./UnitTests/*.csproj");
foreach(var project in projects)
{
DotNetCoreTest(
project.FullPath,
new DotNetCoreTestSettings()
{
Configuration = configuration,
NoBuild = true
});
}
});

Task("UnitTestsOnly")
.Does(() =>
{
Information("Unit testing solution {0} using the {1} configuration...", solution, configuration);
var projects = GetFiles("./UnitTests/*.csproj");
foreach(var project in projects)
{
DotNetCoreTest(
project.FullPath,
new DotNetCoreTestSettings()
{
Configuration = configuration,
NoBuild = true
});
}
});

RunTarget(target);

现在,当我在 Azure DevOps 中运行它时,每个项目都会出现 10 个错误,类似于下面的示例:

"D:\a\1\s\PPIL\MyCompany.MyProduct.IntegrationLayer.sln" (Build target) (1) ->
"D:\a\1\s\PPIL\MC.MP.IL.DatabaseDataReset\MC.MP.IL.DatabaseDataReset.csproj" (default target) (11) ->
D:\a\1\s\PPIL\MC.MP.IL.DatabaseDataReset\MC.MP.IL.DatabaseDataReset.csproj(123,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.VisualStudio.SlowCheetah.3.1.66\build\Microsoft.VisualStudio.SlowCheetah.targets.

我不确定到底是什么问题。可能是因为我们有一个混合项目。可能是因为文件结构。我不知道我需要在 Cake 命令中设置哪些选项或设置以进行构建或恢复。也可能是当我在本地运行它时,我在与 Cake 脚本相同的文件夹中运行它,但它似乎在我的存储库的根文件夹中运行,该文件夹比该解决方案的解决方案文件夹高一个文件夹。

我的脚本哪里出错了?我的恢复步骤看起来很好,除了它只恢复单元测试项目(它依赖于所有其他项目)。是还原吗?构建或恢复中是否缺少我的设置?

最佳答案

所以答案是我获得了所有项目文件并对每个文件运行“NuGetRestore”方法不包括.NET Core UnitTests 项目。然后我可以运行 DotNetCoreRestore 方法,它只恢复 .NET Core UnitTests 项目。

我还发现我应该清理 packages 目录,因为这是一个很好的做法。

关于.net - 使用混合 .NET Core 和框架解决方案的 Azure Devops 中的 Cake 构建脚本失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55385262/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com