【发布时间】:2019-08-18 11:54:04
【问题描述】:
我的 .NET 服务器项目有一个 Cake 构建脚本,它需要在我们的新 Azure DevOps 管道上构建。该脚本在本地工作,但不适用于 Azure DevOps。这可能是因为我有一个基于 .NET Core 2.1 的 unit tests 项目 (xUnit) 而解决方案中的所有其他项目都是 .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 脚本相同的文件夹中运行它,但它似乎在我的存储库的根文件夹中运行,这是该解决方案的解决方案文件夹的上一个文件夹。
我的脚本哪里出错了?我的恢复步骤似乎很好,只是它只恢复了单元测试项目(这确实取决于所有其他项目)。是还原吗?构建或还原中是否缺少我的设置?
【问题讨论】:
-
您是否可能没有对 .Net 框架依赖项进行 Nuget 恢复?看起来你的“恢复”任务只是恢复 .Net Core 包......它也可以解释为什么它“在你的机器上工作” - 你已经安装了所有依赖项 - 也许你可以在干净的 VM 上尝试
标签: .net .net-core azure-devops azure-pipelines cakebuild