【发布时间】:2019-09-11 23:24:51
【问题描述】:
Cake Build 4.0.0 通过执行 MSBuild CLI 命令来运行 NuGetRestore 和 MSBuild 方法。据我了解,Cake 会下载特定版本的 MSBuild。在我的解决方案中,主要是 .NET Framework,但我们的测试项目针对的是 .NET Core 2.1(我们最终会将整个项目迁移到 .NET Core 2.1+,但现在还不能)。我遇到以下错误:
C:\git\OurProduct\PPUXL\tools\.dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(135,5): error : The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1. [C:\git\OurProduct\PPUXL\src\Portals\Core\OurProduct.Tests\OurProduct.Tests.csproj]
所以通常我会下载一个新的 SDK,但我们将在构建代理上运行 Azure DevOps 上的脚本,这些 SDK 不是我们工作站的一部分,而是由 Cake 通过我们运行的 Powershell 脚本下载和编译的。
这是导致错误的代码:
Task("Restore")
.Does(() =>
{
//We need to change this code if we switch from .NET Framework to .NET Core for this project.
NuGetRestore(
solution,
new NuGetRestoreSettings()
{
PackagesDirectory = packagesDirectory
}
);
var projects = GetFiles("./**/*.csproj");
foreach(var project in projects)
{
NuGetRestore(
project,
new NuGetRestoreSettings()
{
PackagesDirectory = packagesDirectory
}
);
}
});
Task("Build")
.Does(() =>
{
MSBuild(
SAMLProject,
new MSBuildSettings()
.SetConfiguration(configuration)
.WithProperty("DeployOnBuild", "true")
.WithProperty("PublishProfile", configuration)
.WithProperty("publishUrl", SAMLDeployDirectory)
.WithProperty("WebPublishMethod", "FileSystem")
);
var projects = GetFiles("./**/*.csproj");
foreach(var project in projects)
{
if(!project.FullPath.Contains("Tests") && !project.FullPath.Contains("SAML"))
{
MSBuild(
project,
new MSBuildSettings()
.SetConfiguration(configuration)
);
}
}
MSBuild(
testProject,
new MSBuildSettings()
.SetConfiguration(configuration)
);
});
我可以通过这样做来防止错误:
Task("Restore")
.Does(() =>
{
//We need to change this code if we switch from .NET Framework to .NET Core for this project.
NuGetRestore(
solution,
new NuGetRestoreSettings()
{
PackagesDirectory = packagesDirectory
}
);
var projects = GetFiles("./**/*.csproj");
foreach(var project in projects)
{
if(!project.FullPath.Contains("Tests") && !project.FullPath.Contains("SAML"))
{
NuGetRestore(
project,
new NuGetRestoreSettings()
{
PackagesDirectory = packagesDirectory
}
);
}
}
});
Task("Build")
.Does(() =>
{
MSBuild(
SAMLProject,
new MSBuildSettings()
.SetConfiguration(configuration)
.WithProperty("DeployOnBuild", "true")
.WithProperty("PublishProfile", configuration)
.WithProperty("publishUrl", SAMLDeployDirectory)
.WithProperty("WebPublishMethod", "FileSystem")
);
var projects = GetFiles("./**/*.csproj");
foreach(var project in projects)
{
if(!project.FullPath.Contains("Tests") && !project.FullPath.Contains("SAML"))
{
MSBuild(
project,
new MSBuildSettings()
.SetConfiguration(configuration)
);
}
}
MSBuild(
testProject,
new MSBuildSettings()
.SetConfiguration(configuration)
);
});
如何使用 Cake 运行构建方法来定位正确的 .NET Core 库?我希望构建全部发生在我的 Powershell 脚本和我的 Cake 脚本中,而不受环境影响。提前致谢。
【问题讨论】:
标签: powershell .net-core msbuild nuget cakebuild