带有 .NET 核心应用程序、MSTest 和 Cake 脚本的 Jenkins 管道
Jenkins pipeline with .NET core app, MSTest, and Cake script
我正在使用 Jenkins 管道,它在带有 MSTest 测试项目的 .NET 核心 Web 应用程序上调用 Cake 构建脚本。
目前我的 Jenkinsfile 非常简单
pipeline {
agent any
stages {
stage('BuildAndTest') {
steps {
checkout scm
bat 'powershell.exe -file ./build.ps1 -Configuration Debug -Target Test -ScriptArgs \'-Name=<my solution name>\''
}
}
}
post {
always {
deleteDir()
}
}
}
我的 build.cake 脚本中正在执行的目标是 GitVersion、RestoreNugetPackages、Build、Test。
当我 运行 在命令提示符下构建 Cake 时,使用来自上面 Jenkinsfile 中 bat 行的完全相同的命令,从检出代码的 Jenkins 工作区文件夹,构建完成成功地。当我从 Jenkins 触发构建时,除测试步骤外,所有步骤都成功。它因几个 'The type or namespace name ... could not be found' 错误而失败。其中一些未找到的是 System、System.String、TestClassAttribute.
它看起来像是专门针对单元测试项目的 nuget 还原问题,但 Cake 脚本中的第一步是 RestoreNugetPackages 并且该步骤中的 Jenkins 控制台输出显示它还原了单元测试的 nuget 包项目,所以所有迹象表明 nuget 恢复工作正常。
同样,运行从命令提示符手动运行整个脚本有效,但在通过 Jenkins 触发时失败。还有其他人 运行 有类似的设置 运行 并解决了这个问题吗?几天来我一直在努力解决这个问题。
下面是 Jenkins 构建的一些输出....
========================================
RestoreNugetPackages
========================================
Executing task: RestoreNugetPackages
MSBuild auto-detection: using msbuild version '15.1.1012.6693' from 'C:\Program Files (x86)\Microsoft Visual Studio17\Community\MSBuild.0\bin'.
Restoring packages for C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\src\mydotnetcore.web.application\mydotnetcore.web.application.csproj...
Restoring packages for C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj...
Committing restore...
Generating MSBuild file C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\obj\mydotnetcore.web.application.UnitTests.csproj.nuget.g.props.
Writing lock file to disk. Path: C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\obj\project.assets.json
Restore completed in 8.5 sec for C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj.
Committing restore...
Generating MSBuild file C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\src\mydotnetcore.web.application\obj\mydotnetcore.web.application.csproj.nuget.g.props.
Writing lock file to disk. Path: C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\src\mydotnetcore.web.application\obj\project.assets.json
Restore completed in 9.95 sec for C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\src\mydotnetcore.web.application\mydotnetcore.web.application.csproj.
NuGet Config files used:
C:\Windows\system32\config\systemprofile\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
Feeds used:
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Finished executing task: RestoreNugetPackages
========================================
Test
========================================
Executing task: Test
Build started, please wait...
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(4,20): error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(14,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(15,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(16,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(17,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(18,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(19,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(20,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(21,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(4,71): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(4,99): error CS0246: The type or namespace name 'FrameworkDisplayName' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(4,122): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(14,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(15,61): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(16,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(17,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(18,68): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(19,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(20,53): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(21,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(1,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(2,7): error CS0246: The type or namespace name 'Microsoft' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(2,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(3,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(11,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(12,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(6,6): error CS0518: Predefined type 'System.Object' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(6,6): error CS0246: The type or namespace name 'TestClassAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(6,6): error CS0246: The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(7,18): error CS0518: Predefined type 'System.Object' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(10,16): error CS0518: Predefined type 'System.Void' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(9,10): error CS0518: Predefined type 'System.Object' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(9,10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(9,10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
An error occurred when executing task 'Test'.
Error: .NET Core CLI: Process returned an error (exit code 1).
我找到了答案,它与恢复 NuGet 包有关。
在我最初的 Cake 构建中,我有一个名为“RestoreNugetPackages 的步骤,看起来像这样
Task("RestoreNugetPackages")
.Does(() =>
{
NuGetRestore(name + ".sln", new NuGetRestoreSettings());
});
这将是为非 .Net Core 应用程序恢复 NuGet 包的正确方法。对于 .Net Core 应用程序,它应该如下所示
Task("RestoreNugetPackages")
.Does(() =>
{
DotNetCoreRestore(name + ".sln");
});
现在,NuGet 包已正确恢复,并且我的测试 运行 符合预期。
我正在使用 Jenkins 管道,它在带有 MSTest 测试项目的 .NET 核心 Web 应用程序上调用 Cake 构建脚本。
目前我的 Jenkinsfile 非常简单
pipeline {
agent any
stages {
stage('BuildAndTest') {
steps {
checkout scm
bat 'powershell.exe -file ./build.ps1 -Configuration Debug -Target Test -ScriptArgs \'-Name=<my solution name>\''
}
}
}
post {
always {
deleteDir()
}
}
}
我的 build.cake 脚本中正在执行的目标是 GitVersion、RestoreNugetPackages、Build、Test。
当我 运行 在命令提示符下构建 Cake 时,使用来自上面 Jenkinsfile 中 bat 行的完全相同的命令,从检出代码的 Jenkins 工作区文件夹,构建完成成功地。当我从 Jenkins 触发构建时,除测试步骤外,所有步骤都成功。它因几个 'The type or namespace name ... could not be found' 错误而失败。其中一些未找到的是 System、System.String、TestClassAttribute.
它看起来像是专门针对单元测试项目的 nuget 还原问题,但 Cake 脚本中的第一步是 RestoreNugetPackages 并且该步骤中的 Jenkins 控制台输出显示它还原了单元测试的 nuget 包项目,所以所有迹象表明 nuget 恢复工作正常。
同样,运行从命令提示符手动运行整个脚本有效,但在通过 Jenkins 触发时失败。还有其他人 运行 有类似的设置 运行 并解决了这个问题吗?几天来我一直在努力解决这个问题。
下面是 Jenkins 构建的一些输出....
========================================
RestoreNugetPackages
========================================
Executing task: RestoreNugetPackages
MSBuild auto-detection: using msbuild version '15.1.1012.6693' from 'C:\Program Files (x86)\Microsoft Visual Studio17\Community\MSBuild.0\bin'.
Restoring packages for C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\src\mydotnetcore.web.application\mydotnetcore.web.application.csproj...
Restoring packages for C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj...
Committing restore...
Generating MSBuild file C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\obj\mydotnetcore.web.application.UnitTests.csproj.nuget.g.props.
Writing lock file to disk. Path: C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\obj\project.assets.json
Restore completed in 8.5 sec for C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj.
Committing restore...
Generating MSBuild file C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\src\mydotnetcore.web.application\obj\mydotnetcore.web.application.csproj.nuget.g.props.
Writing lock file to disk. Path: C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\src\mydotnetcore.web.application\obj\project.assets.json
Restore completed in 9.95 sec for C:\Program Files (x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\src\mydotnetcore.web.application\mydotnetcore.web.application.csproj.
NuGet Config files used:
C:\Windows\system32\config\systemprofile\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
Feeds used:
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Finished executing task: RestoreNugetPackages
========================================
Test
========================================
Executing task: Test
Build started, please wait...
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(4,20): error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(14,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(15,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(16,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(17,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(18,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(19,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(20,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(21,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(4,71): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(4,99): error CS0246: The type or namespace name 'FrameworkDisplayName' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(4,122): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(14,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(15,61): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(16,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(17,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(18,68): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(19,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(20,53): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(21,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(1,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(2,7): error CS0246: The type or namespace name 'Microsoft' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(2,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
C:\Windows\TEMP\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(3,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(11,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
obj\Debug\netcoreapp1.1\mydotnetcore.web.application.UnitTests.AssemblyInfo.cs(12,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(6,6): error CS0518: Predefined type 'System.Object' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(6,6): error CS0246: The type or namespace name 'TestClassAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(6,6): error CS0246: The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(7,18): error CS0518: Predefined type 'System.Object' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(10,16): error CS0518: Predefined type 'System.Void' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(9,10): error CS0518: Predefined type 'System.Object' is not defined or imported [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(9,10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
UnitTest1.cs(9,10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?) [C:\Program Files ( x86)\Jenkins\workspace\mydotnetcore.web.application.release-1.0.0\tests\mydotnetcore.web.application.UnitTests\mydotnetcore.web.application.UnitTests.csproj]
An error occurred when executing task 'Test'.
Error: .NET Core CLI: Process returned an error (exit code 1).
我找到了答案,它与恢复 NuGet 包有关。
在我最初的 Cake 构建中,我有一个名为“RestoreNugetPackages 的步骤,看起来像这样
Task("RestoreNugetPackages")
.Does(() =>
{
NuGetRestore(name + ".sln", new NuGetRestoreSettings());
});
这将是为非 .Net Core 应用程序恢复 NuGet 包的正确方法。对于 .Net Core 应用程序,它应该如下所示
Task("RestoreNugetPackages")
.Does(() =>
{
DotNetCoreRestore(name + ".sln");
});
现在,NuGet 包已正确恢复,并且我的测试 运行 符合预期。