How do I use NUnit in VSTS? - nunit

I am trying to use NUnit 3 within Visual Studio Team System which they seem to have made really hard. I have added in a test assemblies step to the build process and in Advanced execution options -> Path to Custom Test Adapters, I have put in the directory path to NUnitVisualStudioTestAdapter-2.0.0.vsix plugin as advised in the help.
No matter what I do it doesn't seem to find or attempt to run this. It just runs Visual Studio Test and reports that no tests were found. I have also tried putting the test adapter in as a NuGet package and the path to the tools in that, but that doesn't work either.
Has anyone managed to get NUnit working in VSTS and reporting back test results?
The log I get is:
2017-02-07T10:59:26.2778725Z ##[section]Starting: Test Assemblies **\*.Unit.Tests.dll;-:**\obj\**
2017-02-07T10:59:26.2798723Z ==============================================================================
2017-02-07T10:59:26.2798723Z Task : Visual Studio Test
2017-02-07T10:59:26.2798723Z Description : Run tests with Visual Studio test runner
2017-02-07T10:59:26.2798723Z Version : 2.0.10
2017-02-07T10:59:26.2798723Z Author : Microsoft Corporation
2017-02-07T10:59:26.2798723Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkId=835764)
2017-02-07T10:59:26.2798723Z ==============================================================================
2017-02-07T10:59:28.6268742Z ##[warning]No test assemblies found matching the pattern: **\*.Unit.Tests.dll;-:**\obj\**.
2017-02-07T10:59:28.6998724Z ##[section]Finishing: Test Assemblies **\*.Unit.Tests.dll;-:**\obj\**
The unit test DLL file is called App.Web.Unit.Tests.dll.
With system.debug = true set, the log I get is as follows (with some import statements stripped out to fit in 30,000 characters):
2017-02-08T10:44:46.2171630Z ##[section]Starting: Test Assemblies **\*.Unit.Tests.dll;-:**\obj\**
2017-02-08T10:44:46.2251636Z ==============================================================================
2017-02-08T10:44:46.2251636Z Task : Visual Studio Test
2017-02-08T10:44:46.2251636Z Description : Run tests with Visual Studio test runner
2017-02-08T10:44:46.2251636Z Version : 1.0.84
2017-02-08T10:44:46.2251636Z Author : Microsoft Corporation
2017-02-08T10:44:46.2251636Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkId=624539)
2017-02-08T10:44:46.2251636Z ==============================================================================
2017-02-08T10:44:46.2381636Z Preparing task execution handler.
2017-02-08T10:44:52.1286673Z Executing the powershell script: D:\a\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\1.0.84\VSTest.ps1
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddCommand(D:\a\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\1.0.84\VSTest.ps1)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - Add inputParameters
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(testAssembly=**\*Tests.dll;-:**\obj\**)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(testFiltercriteria=)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(runSettingsFile=D:\a\1\s)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(overrideTestrunParameters=)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(codeCoverageEnabled=true)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(runInParallel=false)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(vstestLocationMethod=version)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(vsTestVersion=latest)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(vstestLocation=)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(pathtoCustomTestAdapters=D:\a\1\s\packages)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(otherConsoleOptions=)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(testRunTitle=)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(platform=any cpu)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(configuration=release)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(publishRunAttachments=true)
2017-02-08T10:44:52.4586977Z ##[debug]PowerShellHandler.Execute - Invoke
2017-02-08T10:44:52.5076979Z ##[debug]Entering script VSTest.ps1
2017-02-08T10:44:52.5096982Z ##[debug]vsTestVersion = latest
2017-02-08T10:44:52.5096982Z ##[debug]testAssembly = **\*Tests.dll;-:**\obj\**
2017-02-08T10:44:52.5096982Z ##[debug]testFiltercriteria =
2017-02-08T10:44:52.5096982Z ##[debug]runSettingsFile = D:\a\1\s
2017-02-08T10:44:52.5096982Z ##[debug]codeCoverageEnabled = true
2017-02-08T10:44:52.5106990Z ##[debug]pathtoCustomTestAdapters = D:\a\1\s\packages
2017-02-08T10:44:52.5106990Z ##[debug]overrideTestrunParameters =
2017-02-08T10:44:52.5106990Z ##[debug]otherConsoleOptions =
2017-02-08T10:44:52.5106990Z ##[debug]testRunTitle =
2017-02-08T10:44:52.5106990Z ##[debug]platform = any cpu
2017-02-08T10:44:52.5106990Z ##[debug]configuration = release
2017-02-08T10:44:52.5106990Z ##[debug]publishRunAttachments = true
2017-02-08T10:44:52.5106990Z ##[debug]vstestLocation =
2017-02-08T10:44:52.5476990Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Internal\Microsoft.TeamFoundation.DistributedTask.Task.Internal.psd1'.
2017-02-08T10:44:52.5566992Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Internal\Microsoft.TeamFoundation.DistributedTask.Task.Internal.psm1'.
2017-02-08T10:44:52.5656993Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.LegacySDK.dll'.
2017-02-08T10:44:52.6656999Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Common\Microsoft.TeamFoundation.DistributedTask.Task.Common.psd1'.
2017-02-08T10:44:52.6727018Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Common\Microsoft.TeamFoundation.DistributedTask.Task.Common.psm1'.
2017-02-08T10:44:52.7086999Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.TestResults\Microsoft.TeamFoundation.DistributedTask.Task.TestResults.psm1'.
2017-02-08T10:44:52.7336993Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.CodeCoverage\Microsoft.TeamFoundation.DistributedTask.Task.CodeCoverage.psm1'.
2017-02-08T10:44:52.7406994Z ##[debug]Importing cmdlet 'Invoke-ResultPublisher'.
2017-02-08T10:44:52.7416986Z ##[debug]Importing cmdlet 'Publish-TestResults'.
2017-02-08T10:44:52.7416986Z ##[debug]Importing cmdlet 'Add-BuildArtifactLink'.
2017-02-08T10:44:52.7416986Z ##[debug]Importing cmdlet 'Get-MSBuildLocation'.
2017-02-08T10:44:52.7416986Z ##[debug]Importing cmdlet 'Get-ToolPath'.
2017-02-08T10:44:52.7416986Z ##[debug]Importing cmdlet 'Get-VisualStudioPath'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Get-VssConnection'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Invoke-Ant'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Register-XamarinLicense'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Remove-Environment'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Remove-EnvironmentResources'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Complete-EnvironmentOperation'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Complete-EnvironmentResourceOperation'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Complete-ResourceOperation'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Get-Environment'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Get-EnvironmentProperty'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Get-EnvironmentResources'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Get-ExternalIpAddress'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Get-ParsedSessionVariables'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Add-TaskIssue'.
2017-02-08T10:44:52.7447001Z ##[debug]Importing cmdlet 'Publish-CodeCoverage'.
2017-02-08T10:44:52.7447001Z ##[debug]Exporting cmdlet 'Enable-CodeCoverage'.
2017-02-08T10:44:52.7447001Z ##[debug]Exporting cmdlet 'Publish-CodeCoverage'.
2017-02-08T10:44:52.7447001Z ##[debug]Importing cmdlet 'Enable-CodeCoverage'.
2017-02-08T10:44:52.7447001Z ##[debug]Importing cmdlet 'Publish-CodeCoverage'.
2017-02-08T10:44:52.8017010Z ##[debug]Invoke - Get-TaskVariable cmdlet
2017-02-08T10:44:52.8107020Z ##[debug]Pattern found in solution parameter. Calling Find-Files.
2017-02-08T10:44:52.8107020Z ##[debug]Calling Find-Files with pattern: **\*Tests.dll;-:**\obj\**
2017-02-08T10:44:52.8147008Z ##[debug]FindFiles.FindMatchingFiles(rootFolder = D:\a\1\s, matchPattern = **\*Tests.dll;-:**\obj\**, includeFiles = True, includeFolders = False
2017-02-08T10:44:52.8177007Z ##[debug]FindFiles.GetMatchingItems(includePatterns.Count = 1, excludePatterns.Count = 1, includeFiles = True, includeFolders = False
2017-02-08T10:44:53.4177077Z ##[debug]FindFiles.FindMatchingFiles - Found 0 matches
2017-02-08T10:44:53.4237058Z ##[debug]Found files:
2017-02-08T10:44:53.4467065Z ##[debug]Processed: ##vso[task.logissue type=warning;code=002004;]
2017-02-08T10:44:53.4467065Z
2017-02-08T10:44:53.4467065Z
2017-02-08T10:44:53.4587060Z ##[warning]No test assemblies found matching the pattern: '**\*Tests.dll;-:**\obj\**'.
2017-02-08T10:44:53.4587060Z ##[debug]Processed: ##vso[task.logissue type=warning]No test assemblies found matching the pattern: '**\*Tests.dll;-:**\obj\**'.
2017-02-08T10:44:53.4607060Z ##[debug]Leaving script VSTest.ps1
2017-02-08T10:44:53.4914646Z ##[section]Finishing: Test Assemblies **\*.Unit.Tests.dll;-:**\obj\**
UPDATE:
I have installed the NUnit3TestAdapter package to the unit test project. I have amended the build step in VSTS:
It is version 2.*(preview)
The search pattern is:
*test*.dll
!\obj**
and in Advanced execution options I have Path to Custom Test Adapters set to $(Build.SourcesDirectory)\
I then get this debug information so at least it has found the test adapters if not the tests now:
[command]"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" D:\a\1\s\packages\NUnit3TestAdapter.3.7.0\tools\NUnit3.TestAdapter.dll /EnableCodeCoverage /logger:trx "/TestAdapterPath:\"D:\a\1\s\\\""
Microsoft (R) Test Execution Command Line Tool Version 14.0.25420.1
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Warning: Using Isolation mode to run tests as required by effective Platform:X86 and .Net Framework:Framework35 settings for test run. Use the /inIsolation parameter to suppress this warning.
Information: NUnit Adapter 3.7.0.0: Test execution started
Information: Running all tests in D:\a\1\s\packages\NUnit3TestAdapter.3.7.0\tools\NUnit3.TestAdapter.dll
Information: NUnit failed to load D:\a\1\s\packages\NUnit3TestAdapter.3.7.0\tools\NUnit3.TestAdapter.dll
Information: NUnit Adapter 3.7.0.0: Test execution complete
Warning: No test is available in D:\a\1\s\packages\NUnit3TestAdapter.3.7.0\tools\NUnit3.TestAdapter.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.

The path to custom test adapters must point to the extracted vsix or the extracted NuGet package.
The easiest way to make this work is to add the NUnit Test Adapter NuGet package 2.x/3.x to your unit test project. The VsTest task should automatically detect test runners that are restored to the NuGet packages directory:
Make sure the nunit.framework version and the NUnit adapters versions match. Make sure that both packages are added to your test projects.

The issue in your original post is that the Visual Studio Test task cannot find the test assembly (App.Web.Unit.Tests.dll) you'd like to test. And in your update, after you change the search pattern to "*test.dll", it still cannot find the test assembly. It just find the "NUnit3.TestAdapter.dll" which is the binary file for NUnit test adapter and the binary file does not contains any test method. So you need to check the build log to see if the test assembly is generated correctly in build step and what's the path to it and then set the search pattern according to the path.
Update:
According to the logs you provided, the output files are placed in "D:\a\1\a" folder since you specified argument "/p:OutDir=D:\a\1\a". Try changing the search pattern to:
D:\a\1\a\*.Unit.Tests.dll or $(build.stagingDirectory)\*.Unit.Tests.dll

Related

Azure Pipelines Can't Work With Github Packages

Pretty simple to reproduce:
- task: NuGetCommand#2
displayName: NuGet push
inputs:
command: 'push'
packagesToPush: '$(Pipeline.Workspace)/**/*.nupkg'
nuGetFeedType: 'external'
externalFeedCredentials: 'github-packages'
publishFeedCredentials: 'github-packages'
allowPackageConflicts: true
github-packages is a NuGet Service Connection in the project using a PAT that has full access to my GitHub organization.
I see the following output in the logs
2020-08-08T23:48:41.3089867Z [command]"C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/msbuild.exe" /version /nologo
2020-08-08T23:48:42.7276911Z Caching tool: NuGet 5.4.0 x64
2020-08-08T23:48:42.7397600Z Found tool in cache: NuGet 5.4.0 x64
2020-08-08T23:48:42.7452624Z Resolved from tool cache: 5.4.0
2020-08-08T23:48:42.7453195Z Using version: 5.4.0
2020-08-08T23:48:42.7465530Z Found tool in cache: NuGet 5.4.0 x64
2020-08-08T23:48:42.8246178Z SYSTEMVSSCONNECTION exists true
2020-08-08T23:48:43.1624000Z SYSTEMVSSCONNECTION exists true
2020-08-08T23:48:43.8522322Z [command]C:\windows\system32\chcp.com 65001
2020-08-08T23:48:43.8632712Z Active code page: 65001
2020-08-08T23:48:44.2527739Z SYSTEMVSSCONNECTION exists true
2020-08-08T23:48:44.2733846Z Detected NuGet version 5.4.0.6315 / 5.4.0+d790b66be476cd901a56bd46ada037162097ee21.d790b66be476cd901a56bd46ada037162097ee21
2020-08-08T23:48:44.2752584Z 1b529ea0-989d-42e8-af13-8ba56ff0e7d8 exists true
2020-08-08T23:48:44.2836605Z [command]C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe sources Add -NonInteractive -Name httpsnugetpkggithubcomourorgindexjson -Source https://nuget.pkg.github.com/ourorg/index.json -ConfigFile d:\a\1\Nuget\tempNuGet_3286.config
2020-08-08T23:48:45.7706128Z Package source with Name: httpsnugetpkggithubcomourorgindexjson added successfully.
2020-08-08T23:48:45.7804645Z Using authentication information for the following URI: https://nuget.pkg.github.com/ourorg/index.json
2020-08-08T23:48:45.8355905Z [command]C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe setapikey *** -NonInteractive -Source httpsnugetpkggithubcomourorgindexjson -ConfigFile d:\a\1\Nuget\tempNuGet_3286.config
2020-08-08T23:48:46.4520785Z The API Key '***' was saved for 'https://nuget.pkg.github.com/ourorg/index.json'.
2020-08-08T23:48:46.4686061Z [command]C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe push d:\a\1\Build\M365Management.Console.0.2.83.nupkg -NonInteractive -Source https://nuget.pkg.github.com/ourorg/index.json -ApiKey *** -ConfigFile d:\a\1\Nuget\tempNuGet_3286.config -Verbosity Detailed
2020-08-08T23:48:49.1593595Z Unable to load the service index for source https://nuget.pkg.github.com/ourorg/index.json.
2020-08-08T23:48:49.1594103Z NuGet Version: 5.4.0.6315
2020-08-08T23:48:49.1594906Z Response status code does not indicate success: 401 (Unauthorized).
2020-08-08T23:48:49.1595523Z Using d:\a\_tasks\NuGetCommand_333b11bd-d341-40d9-afcf-b32d5ce6f23b\2.172.0\CredentialProviderV2\plugins\netfx\CredentialProvider.Microsoft\CredentialProvider.Microsoft.exe as a credential provider plugin.
2020-08-08T23:48:49.1596753Z NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://nuget.pkg.github.com/ourorg/index.json. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
the problem seems to be in this line here:
...nuget.exe sources Add -NonInteractive -Name httpsnugetpkggithubcomourorgindexjson -Source https://nuget.pkg.github.com/ourorg/index.json -ConfigFile d:\a\1\Nuget\tempNuGet_3286.config
it adds the external feed as a source, but doesn't use the Service Connection api key when adding it. It only uses the api key in the push command...and so it fails when trying to query the source at https://nuget.pkg.github.com/ourorg/index.json
I'm guessing this is just another broken piece of functionality in Azure DevOps but would appreciate some confirmation.
Thanks.
You might need to use the Basic Authentication as the Authentication method of your Nuget service connection. User your PAT in the Password field. See below screeen:
Go to Project settings-->Service Connections under Pipelines-->Edit your Nuget service connection-->Choose Basic Authentication as Authentication method-->Enter your UserName-->Enter your PAT in the Password field.
In your nuspec file, do you have the repository element?
<repository type="git" url="https://github.com/yourorganization/YourRepo" />
And when you do the push, use the ApiKey instead: The ApiKey should be a PAT with the access rights to write packages

Where to get PKI module for powershell

I need to get pki.psm1 file for the PKI module. Not pspki, not pkiclient, not pkitools, just pki. I need cmdlet Import-Certificate, which isn't in any of the above-mentioned modules, only in PKI. When I tried to copy the module folder from a windows 10 computer with PS 5.1, the psm1 file is missing there and the module therefore doesn't work in lower versions of PS. I need to use it in PS 2.0 if possible, since we have lots of those in our environment. Does anyone know, where can I get complete PKI module?
This Microsoft module was supplied with WMF 5.0 on Windows 10
If you look at the module details it is not compatible below Powershell 3.0:
#{
GUID="{cf094c6b-63d1-4dda-bf70-15a602c4eb2b}"
Author="Microsoft Corporation"
CompanyName="Microsoft Corporation"
Copyright="© Microsoft Corporation. All rights reserved."
ModuleVersion="1.0.0.0"
NestedModules="Microsoft.CertificateServices.PKIClient.Cmdlets"
TypesToProcess = 'pki.types.ps1xml'
HelpInfoUri="http://go.microsoft.com/fwlink/?linkid=390811"
PowerShellVersion='3.0'
CLRVersion='4.0'
CmdletsToExport = #('Add-CertificateEnrollmentPolicyServer', 'Export-Certificate', 'Export-PfxCertificate', 'Get-CertificateAutoEnrollmentPolicy', 'Get-Certificate', 'Get-CertificateNotificationTask', 'Get-CertificateEnrollmentPolicyServer', 'Get-PfxData', 'Import-Certificate', 'Import-PfxCertificate', 'New-CertificateNotificationTask', 'New-SelfSignedCertificate', 'Remove-CertificateNotificationTask', 'Remove-CertificateEnrollmentPolicyServer', 'Set-CertificateAutoEnrollmentPolicy', 'Switch-Certificate', 'Test-Certificate')
}

How to update AssemblyVersion using Update Assembly Info plugin in VSTS?

I want to update the version number of my .exe file using Update Assembly Info plugin.
I am using the following configuration:
But, I keep getting an error
'$(Date:yyyy.MM.dd)$(Rev:.r)' is not a valid parameter for attribute 'AssemblyVersion'
The $(Date:yyyy.MM.dd) and $(Rev:.r) can’t be used as the build-in variable, it can be used in Build number format (Options tab).
The workaround is that:
Include $(Rev:.r) in Build number format, such as $(date:yyyyMMdd)$(rev:.r)
Add PowerShell task to add a new variable (Arguments: -bn $(Build.BuildNumber)
Script:
param(
[string]$bn
)
$d=Get-Date -Format "yyyyMMdd"
$r=$bn.split("{.}")[-1]
Write-Host "##vso[task.setvariable variable=currentVersion]$d$r"
Then use currentVersion variable in subsequent tasks, such as Update Assembly task.

Cake NuGetRestore always wants MSBuild14?

While trying to rig up a solution to build with Cake v0.19.1 on a machine that has only ever known Visual Studio 2017, I can't seem to get NuGetRestore to accept a setting of MSBuildVersion = NuGetMSBuildVersion.MSBuild15.
Is there some magic step to getting a specific MSBuild version into NuGetRestore that I am missing?
Output
...
========================================
RestoreNuGet
========================================
Executing task: RestoreNuGet
Failed to load msbuild Toolset
Could not load file or assembly 'Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
An error occurred when executing task 'RestoreNuGet'.
Error: NuGet: Process returned an error (exit code 1).
Trimmed-down build.cake
var target = Argument("target", "Default");
var solution = "./some-random.sln";
Task("Default")
.Does(() => {
NuGetRestore(
solution,
new NuGetRestoreSettings {
MSBuildVersion = NuGetMSBuildVersion.MSBuild15,
}
);
});
RunTarget(target);
Update: getting NuGet v4
Per #devlead's answer, I pointed the build.ps1 file at the v4.0.0 of NuGet and got this output.
Cannot find the specified version of msbuild: '15'
An error occurred when executing task 'RestoreNuGet'.
Error: NuGet: Process returned an error (exit code 1).
In my full build.cake, I use vswhere for later MSBuildSettings which I can get to dump out the MSBuild path it found (and I confirmed that exe exists in Explorer).
C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/amd64/MSBuild.exe
What you could try is to use the MSBuild alias with the restore target, latest version of MSBuild should have build in NuGet support.
MSBuild(
"./some.sln",
configurator => configurator.WithTarget("restore"));
Make sure you're using the latest version of NuGet.exe, currently it's
v4.0.0 which is the latest version, but you can also see a list of available at https://dist.nuget.org
If you're using the default build.ps1 you could modify it to always download specific version of NuGet.exe
You can do this be remove the Test.Path parts - so it won't look for nuget.exe any where else but your tools folder.
Then change the download uri to not use latest stable (currently v3.5.0) but a specific version by in build.ps1 changing
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
to
$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/v4.0.0/nuget.exe"
will ensure you always download v4.0.0 of the exe.
It's also possible with a little PowerShell to verify correct version in tools, example
if ((Get-ChildItem $NUGET_EXE `
| % VersionInfo `
| % ProductVersion `
| ? { $_ -eq '4.0.0' }|Measure-Object).Count -eq 1)
{
'Correct version'
} else {
'Incorrect version'
}

Can't use TFS 2015 RestApi in Powershell using 'Microsoft.TeamFoundationServer.ExtendedClient' with Powershell

I'm trying to create a powershell module to interact with the new Rest Api using Powershell 3 and the assemblies from the Nuget Packages 'Microsoft.TeamFoundationServer.ExtendedClient'
15.104.0-preview 641 Monday, August 22, 2016
Some more modules are also installed from that one.
I did a basic test and after I loaded the assemblies with Add-Type i have the following assemblies loaded.
Microsoft.VisualStudio.Services.Common - 15.104.25618.0
Microsoft.VisualStudio.Services.WebApi - 15.104.25618.0
Microsoft.VisualStudio.Services.Client - 15.104.25618.0
Microsoft.TeamFoundation.Common - 15.104.25618.0
Microsoft.TeamFoundation.Client - 15.104.25618.0
Microsoft.TeamFoundation.VersionControl.Client - 15.104.25618.0
Microsoft.TeamFoundation.WorkItemTracking.Client - 15.104.25618.0
Microsoft.TeamFoundation.Build.Client - 15.104.25618.0
Microsoft.TeamFoundation.Build.Common - 15.104.25618.0
Microsoft.TeamFoundation.Build2.WebApi - 15.104.25618.0
Microsoft.TeamFoundation.DistributedTask.WebApi - 15.104.25618.0
Newtonsoft.Json - 8.0.3.19514
System.Web.Http - 5.2.20826.0
In order to load System.Web.Http I have to load Newtonsoft.Json.dll version 6.0.8
Add-Type -Path 'D:\Temp\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll'
After I loaded all the dll I tried to create a BuildHttpClien and I get an error.
$cre = New-Object -TypeName 'Microsoft.VisualStudio.Services.Common.VssCredentials' -ArgumentList (Get-Credential)
$build = New-Object -TypeName 'Microsoft.TeamFoundation.Build.WebApi.BuildHttpClient' -ArgumentList ([uri]'{TfsCollectionUrl}'),$cre
when I run this code, I got the following error
Method not found: 'Newtonsoft.Json.JsonSerializerSettings System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.get_SerializerSettings()'. (raised by: New-Object)
I tried the above code in Powershell ISE in Powershell 3.0 compatibility.
The "System.Net.Http.Formatting" and "Newtonsoft.Json" is available in Microsoft.AspNet.WebApi.Client package. To fix the error you get, you can installed this nuget package and then load these two reference from PowerShell.
Add-Type -Path 'D:\Temp\Microsoft.AspNet.WebApi.Client.5.2.2\lib\net45\System.Net.Http.Formatting.dll'
Add-Type -Path 'D:\Temp\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll'
Nuget Packages 'Microsoft.TeamFoundationServer.ExtendedClient' 15.104.0-preview is a prerelease version of Microsoft Team Foundation Server Extended Client. It's suggested to use the latest stable version 14.102.0.
Thanks to Highlight the prerelease should ne be used. It turn out it support API Call for Higher version of TFS than TFS 2015.2 (Some API call use Version 3)
I used the following Nuget Packages. Download them and Copy all the *.dll in a single folder.
id version
-- -------
Microsoft.AspNet.WebApi.Client 5.2.2
Microsoft.AspNet.WebApi.Core 5.2.2
Microsoft.IdentityModel.Clients.ActiveDirectory 2.22.302111727
Microsoft.TeamFoundationServer.Client 14.102.0
Microsoft.TeamFoundationServer.ExtendedClient 14.102.0
Microsoft.VisualStudio.Services.Client 14.102.0
Microsoft.VisualStudio.Services.InteractiveClient 14.102.0
Microsoft.WindowsAzure.ConfigurationManager 1.7.0.0
Newtonsoft.Json 6.0.8
System.IdentityModel.Tokens.Jwt 4.0.0
WindowsAzure.ServiceBus 2.5.1.0
I added the types only from some selected .dll that I put in a list and in a specific order. That seam to be a key part. NewtonSoft.Json is now in first and that work.
Name Assembly
---- --------
NewtonJson Newtonsoft.Json
IdentityModel Microsoft.IdentityModel.Clients.ActiveDirectory
VSCommon Microsoft.VisualStudio.Services.Common
VSCommonWebApi Microsoft.VisualStudio.Services.WebApi
TFCommon Microsoft.TeamFoundation.Common
TFClient Microsoft.TeamFoundation.Client
VCClient Microsoft.TeamFoundation.VersionControl.Client
WITClient Microsoft.TeamFoundation.WorkItemTracking.Client
BuildClient Microsoft.TeamFoundation.Build.Client
BuildCommon Microsoft.TeamFoundation.Build.Common
Build2 Microsoft.TeamFoundation.Build2.WebApi
DistributedTask Microsoft.TeamFoundation.DistributedTask.WebApi
After all of that, I'm able to created some basic types and start my journey into the TFS 2015 Rest web Api .
$credential = [Microsoft.VisualStudio.Services.Common.VssCredentials]::new($true)
PromptType Federated Windows Storage
---------- --------- ------- -------
PromptIfNeeded Microsoft.VisualStudio.Services.Common.WindowsCredential
$buildhttpclient = [Microsoft.TeamFoundation.Build.WebApi.BuildHttpClient]::new($tfscollectionuri,$credential)
$buildhttpclient.GetBuildsAsync('TEAMPROJECTNAME')
Result : {31221, 31220, 31219, 31218...}
Id : 165004
Exception :
Status : RanToCompletion
IsCanceled : False
IsCompleted : True
CreationOptions : None
AsyncState :
IsFaulted : False
AsyncWaitHandle : System.Threading.ManualResetEvent
CompletedSynchronously : False
Into the Result property are the builds.
NOTE: It look the Rest Api limit the number of build result to 1000's.
Still digging around to get more.