Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multitool: Enable cross-platform "dotnet tool" support #1474

Merged
merged 7 commits into from
May 7, 2019

Conversation

dbjorge
Copy link
Contributor

@dbjorge dbjorge commented May 2, 2019

Since .NET Core 2.1, the dotnet CLI tools have supported a concept called Global Tools, which allows a NuGet package containing a console app to be easily installed/distributed in a manner which is consistent with other tools and compatible across multiple platforms/CI systems.

This PR adds support for installing in this fashion to the Multitool. Usage (from any dev/CI environment with v2.1+ of the .NET Core SDK installed) would look like:

dotnet tool install --tool-path ./bin Sarif.Multitool
./bin/sarif-multitool <multitool_args>

This involved adding a netcoreapp2.1 TargetFramework to the Multitool. I presumed that adding this as a built/supported/published target implied you'd want the test projects to build/run for that framework like they do for the other supported frameworks, so this also adds netcoreapp2.1 targets to all the test projects and updates appveyor configuration appropriately to run them. It also updates appveyor to use a 2.1 .NET Core SDK version.

Here is an example of using the multitool from the standard dotnet/core/sdk docker linux container using nupkgs produced with these changes:

PS> type .\dockerfile
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build

# User experience: Install tool from nuget.org
# RUN dotnet tool install --tool-path ./bin Sarif.Multitool

# Local testing experience: Install tool from locally build nupkg
ARG sarif_nupkg_dir=./nupkg
ARG package_version=2.1.0-danielbj.0
COPY ${sarif_nupkg_dir}/* ./nupkg/
RUN dotnet tool install --tool-path ./bin --add-source ./nupkg --version ${package_version} Sarif.Multitool

# Run tool
ENTRYPOINT [ "./bin/sarif-multitool", "--help" ]

PS> docker build -t multitool-helloworld .
Sending build context to Docker daemon  3.846MB
Step 1/6 : FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
 ---> bbae085fa7eb
Step 2/6 : ARG sarif_nupkg_dir=./nupkg
 ---> Using cache
 ---> daca0c15ccc2
Step 3/6 : ARG package_version=2.1.0-danielbj.0
 ---> Using cache
 ---> 1084dbf25a99
Step 4/6 : COPY ${sarif_nupkg_dir}/* ./nupkg/
 ---> Using cache
 ---> d0a3352dc20c
Step 5/6 : RUN dotnet tool install --tool-path ./bin --add-source ./nupkg --version ${package_version} Sarif.Multitool
 ---> Using cache
 ---> a8e37cf4f3b6
Step 6/6 : ENTRYPOINT [ "./bin/sarif-multitool", "--help" ]
 ---> Using cache
 ---> fadcbd027889
Successfully built fadcbd027889
Successfully tagged multitool-helloworld:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

PS> docker run multitool-helloworld
SARIF Multitool 2.1.0
© Microsoft Corporation. All rights reserved.

  validate                 Validate a SARIF file against the schema and against
                           additional correctness rules.

  convert                  Convert a tool output log to SARIF format.

  rewrite                  Transform a SARIF file to a reformatted version.

  transform                Transform a SARIF log to a different version.

  merge                    Merge multiple SARIF files into one.

  rebaseuri                Rebase the URIs in one or more sarif files.

  absoluteuri              Turn all relative Uris into absolute URIs (to be
                           used after rebaseUri is run)

  match-results-forward    Track results run over run by persisting IDs and
                           then matching them forward

  help                     Display more information on a specific command.

  version                  Display version information.

@@ -10,10 +10,8 @@ branches:
- tc-31
- sarif-v1

platform: Any CPU
Copy link
Contributor Author

@dbjorge dbjorge May 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping this is per recommendation from AppVeyor for dotnet test compatibility

@@ -34,27 +34,15 @@ Import-Module -Force $PSScriptRoot\Projects.psm1

$ScriptName = $([io.Path]::GetFileNameWithoutExtension($PSCommandPath))

$ReporterOption = $null
if ($AppVeyor) {
$ReporterOption = "-appveyor"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dropped without replacement because xunit automatically detects this nowadays (see xunit help parameters). I verified that appveyor was still picking up tests as they ran without this.

& ${TestRunnerRootPath}net452\xunit.console.exe $dll $ReporterOption
}
Push-Location $SourceRoot\$project
& dotnet test --no-build --framework $framework --configuration $Configuration
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was required to enable netcoreapp2.1 tests because the entry point has to be netcoreapp2.1 cognizant and xunit.console only releases netcoreapp2.0 DLLs.

This update brings the script more in line with the current recommendations from both dotnet and xunit. It handles correctly detecting the xunit runner based on test projects' PackageReferences and correctly handles the net461 case.

@@ -14,7 +19,7 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.props))\build.props" />

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.2.1" />
<PackageReference Include="CommandLineParser" Version="2.5.0" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was required to test the change in docker; the multitool breaks in docker using 2.2.1 due to commandlineparser/commandline#153

@dbjorge dbjorge changed the title MultiTool: Enable cross-platform "dotnet tool" support Multitool: Enable cross-platform "dotnet tool" support May 2, 2019
Copy link
Member

@michaelcfanning michaelcfanning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@michaelcfanning michaelcfanning merged commit 6ba091a into microsoft:master May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants