Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 05589fe

Browse files
authored
Merge pull request #290 from microsoft/dotnet-core
Get client samples working on .NET Core
2 parents 0945b16 + 5354dfa commit 05589fe

File tree

10 files changed

+174
-6
lines changed

10 files changed

+174
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
// Use IntelliSense to find out which attributes exist for C# debugging
3+
// Use hover for the description of the existing attributes
4+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": ".NET Core Launch (console)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/ClientSamples.netcore.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}",
16+
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
17+
"console": "internalConsole",
18+
"stopAtEntry": false
19+
},
20+
{
21+
"name": ".NET Core Attach",
22+
"type": "coreclr",
23+
"request": "attach",
24+
"processId": "${command:pickProcess}"
25+
}
26+
]
27+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/ClientSamples.netcore.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/ClientSamples.netcore.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"${workspaceFolder}/ClientSamples.netcore.csproj",
36+
"/property:GenerateFullPaths=true",
37+
"/consoleloggerparameters:NoSummary"
38+
],
39+
"problemMatcher": "$msCompile"
40+
}
41+
]
42+
}

ClientLibrary/Samples/ClientSample.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ public ClientSampleContext(Uri url, VssCredentials credentials)
6666

6767
if (credentials == null)
6868
{
69+
#if NETCOREAPP
70+
string pat = Environment.GetEnvironmentVariable(Program.PAT_ENV_VAR);
71+
if (string.IsNullOrEmpty(pat))
72+
{
73+
throw new ArgumentException("On .NET Core, you must set an environment variable " + Program.PAT_ENV_VAR + " with a personal access token.");
74+
}
75+
76+
this.Credentials = new VssBasicCredential("pat", pat);
77+
#else
6978
this.Credentials = new VssClientCredentials();
79+
#endif
7080
}
7181
else
7282
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.TeamFoundation.DistributedTask.WebApi" Version="16.170.0-preview" />
11+
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.170.0-preview" />
12+
<PackageReference Include="Microsoft.VisualStudio.Services.Audit.WebApi" Version="16.170.0-preview" />
13+
<PackageReference Include="Microsoft.VisualStudio.Services.Client" Version="16.170.0-preview" />
14+
<PackageReference Include="Microsoft.VisualStudio.Services.ExtensionManagement.WebApi" Version="16.170.0-preview" />
15+
<PackageReference Include="Microsoft.VisualStudio.Services.InteractiveClient" Version="16.170.0-preview" />
16+
<PackageReference Include="Microsoft.VisualStudio.Services.Notifications.WebApi" Version="16.170.0-preview" />
17+
<PackageReference Include="Microsoft.VisualStudio.Services.Release.Client" Version="16.170.0-preview" />
18+
<PackageReference Include="Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi" Version="16.170.0-preview" />
19+
<PackageReference Include="Microsoft.VisualStudio.Services.ServiceHooks.WebApi" Version="16.170.0-preview" />
20+
<PackageReference Include="System.ComponentModel.Composition" Version="4.7.0" />
21+
</ItemGroup>
22+
23+
</Project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26124.0
5+
MinimumVisualStudioVersion = 15.0.26124.0
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSamples.netcore", "ClientSamples.netcore.csproj", "{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|x64.ActiveCfg = Debug|Any CPU
24+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|x64.Build.0 = Debug|Any CPU
25+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|x86.ActiveCfg = Debug|Any CPU
26+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|x86.Build.0 = Debug|Any CPU
27+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|x64.ActiveCfg = Release|Any CPU
30+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|x64.Build.0 = Release|Any CPU
31+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|x86.ActiveCfg = Release|Any CPU
32+
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|x86.Build.0 = Release|Any CPU
33+
EndGlobalSection
34+
EndGlobal

ClientLibrary/Samples/ClientSamplesProgram.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace Microsoft.Azure.DevOps.ClientSamples
1515
/// </summary>
1616
public class Program
1717
{
18+
public const string PAT_ENV_VAR = "AZURE_DEVOPS_PAT";
19+
1820
public static int Main(string[] args)
1921
{
2022
if (args.Length == 0)
@@ -40,6 +42,16 @@ public static int Main(string[] args)
4042
return -1;
4143
}
4244

45+
#if NETCOREAPP
46+
string checkPat = Environment.GetEnvironmentVariable(PAT_ENV_VAR);
47+
if (string.IsNullOrEmpty(checkPat))
48+
{
49+
Console.WriteLine("On .NET Core, you must set an environment variable " + PAT_ENV_VAR + " with a personal access token.");
50+
return -1;
51+
}
52+
#endif
53+
54+
4355
try
4456
{
4557
ClientSampleUtils.RunClientSampleMethods(connectionUrl, null, area: area, resource: resource, outputPath: outputPath);
@@ -93,7 +105,7 @@ private static void CheckArguments(string[] args, out Uri connectionUrl, out str
93105
if (connectionUrl == null || area == null || resource == null)
94106
{
95107
throw new ArgumentException("Missing required arguments");
96-
}
108+
}
97109
}
98110

99111
private static void ShowUsage() {

ClientLibrary/Samples/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
// General Information about an assembly is controlled through the following
55
// set of attributes. Change these attribute values to modify the information
66
// associated with an assembly.
7-
[assembly: AssemblyTitle("Microsoft Visual Studio Team Services Client Library Samples")]
7+
[assembly: AssemblyTitle("Microsoft Azure DevOps Client Library Samples")]
88
[assembly: AssemblyDescription("")]
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("Microsoft")]
11-
[assembly: AssemblyProduct("Visual Studio Team Services")]
12-
[assembly: AssemblyCopyright("Copyright © 2017")]
11+
[assembly: AssemblyProduct("Azure DevOps")]
12+
[assembly: AssemblyCopyright("Copyright © 2020")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

ClientLibrary/Samples/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ Samples are organized by "area" (service) and "resource". Each sample class show
1010

1111
## Run the samples
1212

13+
1. Clone this repository.
14+
15+
2. Build the solution using .NET Core 3.1 or later.
16+
17+
3. Run `dotnet run --project ClientSamples.netcore.csproj` with the required arguments:
18+
* `/url:{value}`: URL of the account/collection to run the samples against.
19+
* `/area:{value}`: API area (work, wit, notification, git, core, build) to run the client samples for. Use * to include all areas. Be sure to escape the * if you're on a Unix.
20+
* `/resource:{value}`: API resource to run the client samples for. Use * to include all resources. Be sure to escape the * if you're on a Unix.
21+
22+
> **IMPORTANT**: some samples are destructive. It is recommended that you run these samples against a test account.
23+
24+
## Run the samples - .NET Framework
25+
1326
1. Clone this repository and open in Visual Studio (2015 or later)
1427

1528
2. Build the solution (you may need to restore the required NuGet packages first)

ClientLibrary/Samples/Release/ReleasesSample.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ public IEnumerable<Deployment> ListDeploymentsForAGivenDefinitionId()
602602
return deployments;
603603
}
604604

605+
#if NETCOREAPP
606+
// not working in netcore3.1
607+
#else
605608
[ClientSampleMethod]
606609
public IEnumerable<Deployment> ListAllDeploymentsForASpecificReleaseDefinitionId()
607610
{
@@ -642,6 +645,7 @@ public IEnumerable<Deployment> ListAllDeploymentsForASpecificReleaseDefinitionId
642645

643646
return deployments;
644647
}
648+
#endif
645649

646650
[ClientSampleMethod]
647651
public System.IO.Stream GetLogsOfReleaseTask()

ClientLibrary/Samples/Serviceendpoint/EndpointsSample.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System;
1+
#if NETCOREAPP
2+
// not working in netcore3.1
3+
#else
4+
using System;
25
using System.Collections.Generic;
36
using Microsoft.TeamFoundation.Core.WebApi;
47
using Microsoft.VisualStudio.Services.FormInput;
@@ -178,4 +181,4 @@ public void DeleteServiceEndpoint()
178181
}
179182
}
180183
}
181-
184+
#endif

0 commit comments

Comments
 (0)