我的.NET服务器项目有一个蛋糕构建脚本,该脚本需要在新的Azure DevOps管道上构建。该脚本在本地可用,但不适用于Azure DevOps。造成这种情况的可能原因可能是我在.NET Core 2.1上构建了一个单元测试项目(xUnit),而解决方案中的所有其他项目都是.NET Framework 4.6.1(我们刚刚在xUnit项目中添加了我唯一的选项是将其添加为.NET Core项目)。
我写了我的蛋糕脚本,该脚本在本地有效。看起来像这样:
//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脚本的同一文件夹中运行,但是它似乎在我的仓库的根文件夹中运行,该文件夹是此解决方案的解决方案文件夹中的一个文件夹。
我的脚本哪里出问题了?我的还原步骤似乎很好,除了它只还原UnitTests项目(它确实取决于所有其他项目)。是还原吗?在构建或还原中是否缺少我的设置?提前致谢。
因此答案是,我获得了所有项目文件并在每个文件上运行“ NuGetRestore”方法,但.NET Core UnitTests项目除外。然后,我可以运行DotNetCoreRestore方法,该方法仅还原.NET Core UnitTests项目。
我还发现我应该清理packages目录,因为这是一个好习惯。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句