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

Commit

Permalink
Merge pull request #290 from microsoft/dotnet-core
Browse files Browse the repository at this point in the history
Get client samples working on .NET Core
  • Loading branch information
vtbassmatt authored Jun 25, 2020
2 parents 0945b16 + 5354dfa commit 05589fe
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 6 deletions.
27 changes: 27 additions & 0 deletions ClientLibrary/Samples/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/ClientSamples.netcore.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
42 changes: 42 additions & 0 deletions ClientLibrary/Samples/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/ClientSamples.netcore.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/ClientSamples.netcore.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/ClientSamples.netcore.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
10 changes: 10 additions & 0 deletions ClientLibrary/Samples/ClientSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ public ClientSampleContext(Uri url, VssCredentials credentials)

if (credentials == null)
{
#if NETCOREAPP
string pat = Environment.GetEnvironmentVariable(Program.PAT_ENV_VAR);
if (string.IsNullOrEmpty(pat))
{
throw new ArgumentException("On .NET Core, you must set an environment variable " + Program.PAT_ENV_VAR + " with a personal access token.");
}

this.Credentials = new VssBasicCredential("pat", pat);
#else
this.Credentials = new VssClientCredentials();
#endif
}
else
{
Expand Down
23 changes: 23 additions & 0 deletions ClientLibrary/Samples/ClientSamples.netcore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TeamFoundation.DistributedTask.WebApi" Version="16.170.0-preview" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.170.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Services.Audit.WebApi" Version="16.170.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Services.Client" Version="16.170.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Services.ExtensionManagement.WebApi" Version="16.170.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Services.InteractiveClient" Version="16.170.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Services.Notifications.WebApi" Version="16.170.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Services.Release.Client" Version="16.170.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Services.ServiceEndpoints.WebApi" Version="16.170.0-preview" />
<PackageReference Include="Microsoft.VisualStudio.Services.ServiceHooks.WebApi" Version="16.170.0-preview" />
<PackageReference Include="System.ComponentModel.Composition" Version="4.7.0" />
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions ClientLibrary/Samples/ClientSamples.netcore.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientSamples.netcore", "ClientSamples.netcore.csproj", "{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|x64.ActiveCfg = Debug|Any CPU
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|x64.Build.0 = Debug|Any CPU
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|x86.ActiveCfg = Debug|Any CPU
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Debug|x86.Build.0 = Debug|Any CPU
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|Any CPU.Build.0 = Release|Any CPU
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|x64.ActiveCfg = Release|Any CPU
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|x64.Build.0 = Release|Any CPU
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|x86.ActiveCfg = Release|Any CPU
{C9F7FF01-ACDB-4866-B185-AC06D45E09EC}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
14 changes: 13 additions & 1 deletion ClientLibrary/Samples/ClientSamplesProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace Microsoft.Azure.DevOps.ClientSamples
/// </summary>
public class Program
{
public const string PAT_ENV_VAR = "AZURE_DEVOPS_PAT";

public static int Main(string[] args)
{
if (args.Length == 0)
Expand All @@ -40,6 +42,16 @@ public static int Main(string[] args)
return -1;
}

#if NETCOREAPP
string checkPat = Environment.GetEnvironmentVariable(PAT_ENV_VAR);
if (string.IsNullOrEmpty(checkPat))
{
Console.WriteLine("On .NET Core, you must set an environment variable " + PAT_ENV_VAR + " with a personal access token.");
return -1;
}
#endif


try
{
ClientSampleUtils.RunClientSampleMethods(connectionUrl, null, area: area, resource: resource, outputPath: outputPath);
Expand Down Expand Up @@ -93,7 +105,7 @@ private static void CheckArguments(string[] args, out Uri connectionUrl, out str
if (connectionUrl == null || area == null || resource == null)
{
throw new ArgumentException("Missing required arguments");
}
}
}

private static void ShowUsage() {
Expand Down
6 changes: 3 additions & 3 deletions ClientLibrary/Samples/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Microsoft Visual Studio Team Services Client Library Samples")]
[assembly: AssemblyTitle("Microsoft Azure DevOps Client Library Samples")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Visual Studio Team Services")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyProduct("Azure DevOps")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
13 changes: 13 additions & 0 deletions ClientLibrary/Samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ Samples are organized by "area" (service) and "resource". Each sample class show

## Run the samples

1. Clone this repository.

2. Build the solution using .NET Core 3.1 or later.

3. Run `dotnet run --project ClientSamples.netcore.csproj` with the required arguments:
* `/url:{value}`: URL of the account/collection to run the samples against.
* `/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.
* `/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.

> **IMPORTANT**: some samples are destructive. It is recommended that you run these samples against a test account.
## Run the samples - .NET Framework

1. Clone this repository and open in Visual Studio (2015 or later)

2. Build the solution (you may need to restore the required NuGet packages first)
Expand Down
4 changes: 4 additions & 0 deletions ClientLibrary/Samples/Release/ReleasesSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@ public IEnumerable<Deployment> ListDeploymentsForAGivenDefinitionId()
return deployments;
}

#if NETCOREAPP
// not working in netcore3.1
#else
[ClientSampleMethod]
public IEnumerable<Deployment> ListAllDeploymentsForASpecificReleaseDefinitionId()
{
Expand Down Expand Up @@ -642,6 +645,7 @@ public IEnumerable<Deployment> ListAllDeploymentsForASpecificReleaseDefinitionId

return deployments;
}
#endif

[ClientSampleMethod]
public System.IO.Stream GetLogsOfReleaseTask()
Expand Down
7 changes: 5 additions & 2 deletions ClientLibrary/Samples/Serviceendpoint/EndpointsSample.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
#if NETCOREAPP
// not working in netcore3.1
#else
using System;
using System.Collections.Generic;
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.VisualStudio.Services.FormInput;
Expand Down Expand Up @@ -178,4 +181,4 @@ public void DeleteServiceEndpoint()
}
}
}

#endif

0 comments on commit 05589fe

Please sign in to comment.