上篇文章介绍了GitLab CI的持续集成配置方法,本篇文章将主要介绍NUnit的持续集成和遇到的一些坑html
1.NUnit单元测试持续集成git
- 下载NUnit.3.4.1.msi,https://github.com/nunit/nunit/releases/tag/3.4.1
- 在持续集成的CI服务器上,安装msi,并将安装路径从C:\Program Files (x86)改到C:\NUnit,由于shell脚本好像处理括号或者空格比较麻烦。
- 将以前的shell脚本的/p:Configuration=Release改为/p:Configuration=Debug
- 构建shell脚本命令
C:\NUnit\nunit-console\nunit3-console.exe " ConsoleApplication1 "【所有脚本】github
stages: - build job: stage: build script: - echo "Restoring NuGet Packages..." - C:\test\nuget.exe restore "ConsoleApplication1.sln" - echo "Solution Build..." - C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe /p:Configuration=Debug /p:Platform="Any CPU" /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /verbosity:quiet "ConsoleApplication1.sln" - C:\NUnit\nunit-console\nunit3-console.exe " ConsoleApplication1.sln" tags: except: - tags
2.遇到的问题shell
2.1 一台机子配置多个CI服务windows
原理就是用sc命令建立一个gitlab_runner的服务,以下段代码安全
sc create gitLab_FrameWork binPath= "D:\Kog_ECode\Kog_Framework\gitlab-ci-multi-runner-windows-amd64.exe run --working-directory D:\Kog_ECode\Kog_Framework --config D:\Kog_ECode\Kog_Framework\config.toml --service gitlab-runner --syslog"核心是BindPath,bindPath如何填写,参考能够把gitlab-runner服务的搞进来,改个路径便可服务器
2.2 MSBuild 编译错误工具
MSBuild间接引用会报错,我直接安装的vs2015,网上说安装vs2015编译工具和netframework的sdk版本便可解决gitlab
错误以下:单元测试
error CS0012: The type 'XXXXXXX' is defined in an assembly that is not referenced.You must add a reference to assembly 'System.XXXXXX, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.Microsoft Build Tools 2015 下载地址 :
https://www.microsoft.com/en-in/download/details.aspx?id=48159
Microsoft Build Tools 2013 下载地址:
https://www.microsoft.com/en-gb/download/details.aspx?id=40760
2.3 MSB4019
CI服务器用msbuild命令编译时候,会出现MBS4019(想看到错误编号,只要把命令/verbosity:quiet 改为/verbosity=diagnostic便可)
错误:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\XXXX.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.)【解决办法】
1>安装Microsoft Visual Studio 2015 Shell (独立),Visual Studio 2015 Isolated Shell(须要有注册Connect帐号)
2>把缺失的target拷贝上去,或者删除
2.4 powershell脚本 执行不成功的解决办法
一、将PowerShell的脚本内容保存到一个.ps1为后缀的文件中。
二、双击执行此ps1文件颇有可能没法执行,提示:没法加载文件 D:\PowerShell\test\myfirst1.ps1,由于在此系统中禁止执行脚本。
三、运行get-executionpolicy,若是结果是Restricted,那表示禁止执行脚本。四、执行以下命令,下降系统的安全性,容许执行脚本:set-executionpolicy -executionpolicy unrestricted
【参考资料】