Skip to content
Akira Sugiura edited this page Feb 22, 2016 · 2 revisions

If you want to use Prig in AppVeyor, you have to perform the following steps:

  1. Create Install Script
  2. Install Prig through Chocolatey
  3. Identify Prig installed path and set working directory
  4. Register Prig
  5. Install default source
  6. Revert working directory
  7. Create Build Script
  8. Build normal solution
  9. Build custom Indirection Delegate solution
  10. Create Test Script
  11. Test normal solution
  12. Test with another profiler

Now, let me explain the sample project on the AppVeyor Prig.Samples as an example.

It becomes available that you create the install script by setting Install script to PS in SETTINGS - Environment. The whole script is the below:

# Install Prig through Chocolatey
cinst prig

# Identify Prig installed path and set working directory
$prigDlls = Resolve-Path ($env:USERPROFILE + '\AppData\Local\Microsoft\VisualStudio\*\Extensions\*\Prig.dll') | dir | sort LastWriteTime -Descending
Push-Location $prigDlls[0].DirectoryName
[System.Environment]::CurrentDirectory = $PWD

# Register Prig
& .\Register-Prig.ps1

# Install test runner as the source for processing with Prig
prig install "NUnit" -source 'C:\Tools\NUnit\bin'

# Revert working directory
Pop-Location
[System.Environment]::CurrentDirectory = $PWD

Let me explain the detail for each processing.

Execute the following command to install Prig through Chocolatey:

cinst prig

You don't have to specify -y option because AppVeyor specifies it automatically.

Prig will be installed as VSIX. Normally, you install the rest from Visual Studio. However, in the AppVeyor, you have to do that in the console. At first, identify the directory that Prig was installed, and change the location to there:

$prigDlls = Resolve-Path ($env:USERPROFILE + '\AppData\Local\Microsoft\VisualStudio\*\Extensions\*\Prig.dll') | dir | sort LastWriteTime -Descending
Push-Location $prigDlls[0].DirectoryName
[System.Environment]::CurrentDirectory = $PWD

Execute the following script to install the rest that are copying exe, registering environment variables and registering the profiler to registry and so on:

& .\Register-Prig.ps1

Register test runner as the source that is executed with Prig:

prig install "NUnit" -source 'C:\Tools\NUnit\bin'

For your information, the installed location of the test runners that are supported by AppVeyor is described here.

After installation is finished, revert the working directory:

Pop-Location
[System.Environment]::CurrentDirectory = $PWD

It becomes available that you create the build script by setting Build script to PS in SETTINGS - Build. The whole script is the below(the descriptions that are same as other are snipped):

# Build normal solution
nuget restore '01.QuickTour\QuickTour.sln'
msbuild '01.QuickTour\QuickTour.sln'

...(snip)...

# Build custom Indirection Delegate solution
nuget restore '12.ThreeOrMoreOutRef\12.ThreeOrMoreOutRef.sln'
msbuild '12.ThreeOrMoreOutRef\12.ThreeOrMoreOutRef.sln' '/t:MyDelegates'
prig update All -delegate "$((dir .\12.ThreeOrMoreOutRef\MyDelegates\bin\Debug\MyDelegates.dll).FullName)"
msbuild '12.ThreeOrMoreOutRef\12.ThreeOrMoreOutRef.sln' '/t:ThreeOrMoreOutRef;ThreeOrMoreOutRefTest;UntestableLibrary'

Let's look the point of each processing.

In normal case, you just restore the NuGet packages and build the solution as the help of AppVeyor explained:

nuget restore '01.QuickTour\QuickTour.sln'
msbuild '01.QuickTour\QuickTour.sln'

In the case using custom Indirection Delegate as Replace Three or More out ref Parameter Method explained, you must be careful:

nuget restore '12.ThreeOrMoreOutRef\12.ThreeOrMoreOutRef.sln'
msbuild '12.ThreeOrMoreOutRef\12.ThreeOrMoreOutRef.sln' '/t:MyDelegates'
prig update All -delegate "$((dir .\12.ThreeOrMoreOutRef\MyDelegates\bin\Debug\MyDelegates.dll).FullName)"
msbuild '12.ThreeOrMoreOutRef\12.ThreeOrMoreOutRef.sln' '/t:ThreeOrMoreOutRef;ThreeOrMoreOutRefTest;UntestableLibrary'

Restoring NuGet packages is same as the above, but you have to build only the project that contains custom Indirection Delegate next. Then, execute prig update command to install custom Indirection Delegate. Finally, build the other projects.

It becomes available that you create the test script by setting Test script to PS in SETTINGS - Tests. The whole script is the below(the descriptions that are same as other are snipped):

# Test normal solution
Push-Location "01.QuickTour\QuickTourTest\bin\Debug"
[System.Environment]::CurrentDirectory = $PWD
$env:URASANDESU_PRIG_CURRENT_DIRECTORY = $PWD
$env:URASANDESU_PRIG_TARGET_PROCESS_NAME = "nunit-agent"
prig run -process "C:\Tools\NUnit\bin\nunit-console.exe" -arguments "QuickTourTest.dll /domain=None /framework=v4.0"
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestResult.xml))
Pop-Location
[System.Environment]::CurrentDirectory = $PWD

...(snip)...

# Test with another profiler
Push-Location "07.ProfilersChain"
[System.Environment]::CurrentDirectory = $PWD
prig install NUnit -source (Resolve-Path .\packages\NUnit.Runners.2.6.4\tools).Path
& .\runcoverages.ps1
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestResult.xml))
Pop-Location
[System.Environment]::CurrentDirectory = $PWD

...(snip)...

Let's look the point of each processing.

In the normal solution, at first, change the directory to the location that test target dll exists:

Push-Location "01.QuickTour\QuickTourTest\bin\Debug"
[System.Environment]::CurrentDirectory = $PWD

Next, set the working directory for Prig and the process name that Prig should attach. And, execute tests:

$env:URASANDESU_PRIG_CURRENT_DIRECTORY = $PWD
$env:URASANDESU_PRIG_TARGET_PROCESS_NAME = "nunit-agent"
prig run -process "C:\Tools\NUnit\bin\nunit-console.exe" -arguments "QuickTourTest.dll /domain=None /framework=v4.0"

Follow AppVeyor help, push the test result:

$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestResult.xml))

Finally, revert the working directory:

Pop-Location
[System.Environment]::CurrentDirectory = $PWD

In the case that cooperates with another profiler as Profilers Chain explained, you have already prepared a bat file, so you can execute it. Also change the working directory to the location that bat expects:

Push-Location "07.ProfilersChain"
[System.Environment]::CurrentDirectory = $PWD

Test runner is also restored independently, so you have to register as the source newly:

prig install NUnit -source (Resolve-Path .\packages\NUnit.Runners.2.6.4\tools).Path

Execute prepared bat file:

& .\runcoverages.ps1

In the end, same as the normal case, push the test results, and revert the working directory:

$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestResult.xml))
Pop-Location
[System.Environment]::CurrentDirectory = $PWD
Clone this wiki locally