Fix merge

This commit is contained in:
William Li 2018-09-09 21:16:11 -07:00
parent f3c7f5ed78
commit 97817b0ca2
19 changed files with 5 additions and 597 deletions

View file

@ -1,60 +0,0 @@
Signing .NET Core Global Tool Packages
===============================
To create a signed package for your Dotnet Tool, you will need to create a signed shim. If a shim is found in the nupkg during `dotnet tool install`, it is used instead of creating one on consumer's machine.
To create a signed shim, you need to add the following extra property in you project file:
```
<PackAsToolShimRuntimeIdentifiers>[list of RIDs]</PackAsToolShimRuntimeIdentifiers>
```
When this property is set, `dotnet pack` will generate a shim in the package (nupkg). Assuming all other other content is signed, after you sign the shim you can sign the nupkg.
Example:
```xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<PackAsTool>true</PackAsTool>
<PackAsToolShimRuntimeIdentifiers>win-x64;win-x86;osx-x64</PackAsToolShimRuntimeIdentifiers>
</PropertyGroup>
</Project>
```
The result nupkg will have packaged shim included. Of course `dotnet pack` does not sign the shim or the package. The mechanism for that depends on your processes. The structure of the unzipped nupkg is:
```
│ shimexample.nuspec
│ [Content_Types].xml
├───package
│ └───services
│ └───metadata
│ └───core-properties
│ 9c20d06e1d8b4a4ba3e126f30013ef32.psmdcp
├───tools
│ └───netcoreapp2.1
│ └───any
│ │ DotnetToolSettings.xml
│ │ shimexample.deps.json
│ │ shimexample.dll
│ │ shimexample.pdb
│ │ shimexample.runtimeconfig.json
│ │
│ └───shims
│ ├───osx-x64
│ │ shimexample
│ │
│ ├───win-x64
│ │ shimexample.exe
│ │
│ └───win-x86
│ shimexample.exe
└───_rels
.rels
```

View file

@ -1,29 +0,0 @@
Tool NuGet package format
-------------------------------------------
The most straightforward way to create a .NET tool package is to run `dotnet pack` with `PackAsTool` property set in the project file. However, if your build process is highly customized, `dotnet publish` may not create the right package for you. In this case, you can create a NuGet package for your tool using a *nuspec* file and explicitly placing assets into the NuGet package following these rules.
- The NuGet package has only _/tools_ folder under the root and does **not** contain any other folders; do not include folders like _/lib_, _/content_, etc.
- Under _/tools_ folder, the subfolders must be structured with pattern _target framework short version/RID_. For example, tool assets targeting .NET core framework V2.1 that are portable across platforms should be in the folder _tools/netcoreapp2.1/any_.
Let's call assets under every _tools/target framework short version/RID_ combination "per TFM-RID assets" :
- There is a DotnetToolSettings.xml for every "per TFM-RID assets".
- The package type is DotnetTool.
- Each set of TFM-RID assets should have all the dependencies the tool requires to run. The TFM-RID assets should work correctly after being copied via `xcopy` to another machine, assuming that machine has the correct runtime version and RID environment.
- For portable app, there must be runtimeconfig.json for every "per TFM-RID assets".
# Remark:
- Currently, only portable apps are supported so the RID must be _any_.
- Only one tool per tool package.
DotnetToolSettings.xml:
Example:
```xml
<?xml version="1.0" encoding="utf-8" ?>
<DotNetCliTool>
<Commands>
<Command Name="%sayhello%" EntryPoint="%console.dll%" Runner="dotnet" />
</Commands>
</DotNetCliTool>
```
Currently only configurable part is command name: _sayhello_ and entry point: _console.dll_. Command Name is what the user will type in their shell to invoke the command. Entry point is the relative path to the entry dll with main.

View file

@ -1,8 +1,5 @@
<Project>
<!-- This test asset needs to import the general dir.props in order to get the SdkNugetVersion property.
This is why it also needs to explicitly set DisableImplicitFrameworkReferences to false. -->
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
<PropertyGroup>

View file

@ -1,8 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.2</TargetFrameworks>
</PropertyGroup>
</Project>

View file

@ -1,12 +0,0 @@
using System;
namespace MultitargetedCS
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View file

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.2</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
</Project>

View file

@ -1,8 +0,0 @@
// Learn more about F# at http://fsharp.org
open System
[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
0 // return an integer exit code

View file

@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>MultitargetedVB</RootNamespace>
<TargetFrameworks>netcoreapp2.2</TargetFrameworks>
</PropertyGroup>
</Project>

View file

@ -1,7 +0,0 @@
Imports System
Module Program
Sub Main(args As String())
Console.WriteLine("Hello World!")
End Sub
End Module

View file

@ -1,18 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
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
EndGlobal

View file

@ -1,8 +1,8 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<BundledTemplate Include="Microsoft.DotNet.Common.ItemTemplates" Version="$(MicrosoftDotNetCommonItemTemplatesPackageVersion)" />
<BundledTemplate Include="Microsoft.DotNet.Common.ProjectTemplates.2.2" Version="$(MicrosoftDotNetCommonProjectTemplates20PackageVersion)" />
<BundledTemplate Include="Microsoft.DotNet.Test.ProjectTemplates.2.2" Version="$(MicrosoftDotNetTestProjectTemplates20PackageVersion)" />
<BundledTemplate Include="Microsoft.DotNet.Common.ProjectTemplates.2.2" Version="$(MicrosoftDotNetCommonProjectTemplates22PackageVersion)" />
<BundledTemplate Include="Microsoft.DotNet.Test.ProjectTemplates.2.2" Version="$(MicrosoftDotNetTestProjectTemplates22PackageVersion)" />
<BundledTemplate Include="Microsoft.Dotnet.Wpf.ProjectTemplates" Version="$(MicrosoftDotnetWpfProjectTemplatesPackageVersion)" />
<BundledTemplate Include="Microsoft.Dotnet.WinForms.ProjectTemplates" Version="$(MicrosoftDotnetWinFormsProjectTemplatesPackageVersion)" />

View file

@ -18,7 +18,7 @@
<PropertyGroup>
<MicrosoftNETCoreAppPackageVersion>3.0.0-preview1-26909-04</MicrosoftNETCoreAppPackageVersion>
<!-- https://github.com/dotnet/cli/issues/9851 -->
<MicrosoftNETCoreDotNetHostResolverPackageVersion_ForMSBuildSdkResolverOnly>3.0.0-preview1-26816-04</MicrosoftNETCoreDotNetHostResolverPackageVersion_ForMSBuildSdkResolverOnly>
@ -28,7 +28,6 @@
<MicrosoftDotNetCommonItemTemplatesPackageVersion>1.0.2-beta4-20180803-1918431</MicrosoftDotNetCommonItemTemplatesPackageVersion>
<MicrosoftDotNetCommonProjectTemplates22PackageVersion>$(MicrosoftDotNetCommonItemTemplatesPackageVersion)</MicrosoftDotNetCommonProjectTemplates22PackageVersion>
<MicrosoftDotNetTestProjectTemplates22PackageVersion>1.0.2-beta4-20180821-1966911</MicrosoftDotNetTestProjectTemplates22PackageVersion>
<MicroBuildCorePackageVersion>0.2.0</MicroBuildCorePackageVersion>
<NUnit3TemplatesVersion>1.5.1</NUnit3TemplatesVersion>
</PropertyGroup>

0
build/run-build.ps1 Normal file
View file

View file

@ -113,6 +113,6 @@ if ($NoBuild)
else
{
dotnet msbuild build.proj /bl:msbuild.generatepropsfile.binlog /p:Architecture=$Architecture /p:GeneratePropsFile=true /t:WriteDynamicPropsToStaticPropsFiles $ExtraParametersNoTargets
dotnet msbuild build.proj /bl:msbuild.generatepropsfile.binlog /m /v:normal /fl /flp:v=diag /bl /p:Architecture=$Architecture $ExtraParameters
dotnet msbuild build.proj /bl:msbuild.mainbuild.binlog /m /v:normal /fl /flp:v=diag /bl /p:Architecture=$Architecture $ExtraParameters
if($LASTEXITCODE -ne 0) { throw "Failed to build" }
}

View file

@ -1,135 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace Microsoft.DotNet.MSBuildSdkResolver
{
internal static partial class Interop
{
internal static readonly bool RunningOnWindows =
#if NET46
// Not using RuntimeInformation on NET46 to avoid non-in-box framework API,
// which create deployment problems for the resolver.
Path.DirectorySeparatorChar == '\\';
#else
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#endif
static Interop()
{
if (RunningOnWindows)
{
PreloadWindowsLibrary("hostfxr.dll");
}
}
// MSBuild SDK resolvers are required to be AnyCPU, but we have a native dependency and .NETFramework does not
// have a built-in facility for dynamically loading user native dlls for the appropriate platform. We therefore
// preload the version with the correct architecture (from a corresponding sub-folder relative to us) on static
// construction so that subsequent P/Invokes can find it.
private static void PreloadWindowsLibrary(string dllFileName)
{
string basePath = Path.GetDirectoryName(typeof(Interop).Assembly.Location);
string architecture = IntPtr.Size == 8 ? "x64" : "x86";
string dllPath = Path.Combine(basePath, architecture, dllFileName);
// return value is intentially ignored as we let the subsequent P/Invokes fail naturally.
LoadLibraryExW(dllPath, IntPtr.Zero, LOAD_WITH_ALTERED_SEARCH_PATH);
}
// lpFileName passed to LoadLibraryEx must be a full path.
private const int LOAD_WITH_ALTERED_SEARCH_PATH = 0x8;
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr LoadLibraryExW(string lpFileName, IntPtr hFile, int dwFlags);
[Flags]
internal enum hostfxr_resolve_sdk2_flags_t : int
{
disallow_prerelease = 0x1,
}
internal enum hostfxr_resolve_sdk2_result_key_t : int
{
resolved_sdk_dir = 0,
global_json_path = 1,
}
internal static class Windows
{
private const CharSet UTF16 = CharSet.Unicode;
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = UTF16)]
internal delegate void hostfxr_resolve_sdk2_result_fn(
hostfxr_resolve_sdk2_result_key_t key,
string value);
[DllImport("hostfxr", CharSet = UTF16, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
internal static extern int hostfxr_resolve_sdk2(
string exe_dir,
string working_dir,
hostfxr_resolve_sdk2_flags_t flags,
hostfxr_resolve_sdk2_result_fn result);
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = UTF16)]
internal delegate void hostfxr_get_available_sdks_result_fn(
int sdk_count,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]
string[] sdk_dirs);
[DllImport("hostfxr", CharSet = UTF16, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
internal static extern int hostfxr_get_available_sdks(
string exe_dir,
hostfxr_get_available_sdks_result_fn result);
}
internal static class Unix
{
// Ansi marhsaling on Unix is actually UTF8
private const CharSet UTF8 = CharSet.Ansi;
private static string PtrToStringUTF8(IntPtr ptr) => Marshal.PtrToStringAnsi(ptr);
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = UTF8)]
internal delegate void hostfxr_resolve_sdk2_result_fn(
hostfxr_resolve_sdk2_result_key_t key,
string value);
[DllImport("hostfxr", CharSet = UTF8, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
internal static extern int hostfxr_resolve_sdk2(
string exe_dir,
string working_dir,
hostfxr_resolve_sdk2_flags_t flags,
hostfxr_resolve_sdk2_result_fn result);
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = UTF8)]
internal delegate void hostfxr_get_available_sdks_result_fn(
int sdk_count,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]
string[] sdk_dirs);
[DllImport("hostfxr", CharSet = UTF8, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
internal static extern int hostfxr_get_available_sdks(
string exe_dir,
hostfxr_get_available_sdks_result_fn result);
[DllImport("libc", CharSet = UTF8, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr realpath(string path, IntPtr buffer);
[DllImport("libc", ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
private static extern void free(IntPtr ptr);
internal static string realpath(string path)
{
var ptr = realpath(path, IntPtr.Zero);
var result = PtrToStringUTF8(ptr);
free(ptr);
return result;
}
}
}
}

View file

@ -1,76 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics;
namespace Microsoft.DotNet.MSBuildSdkResolver
{
internal static class NETCoreSdkResolver
{
public sealed class Result
{
/// <summary>
/// Path to .NET Core SDK selected by hostfxr (e.g. C:\Program Files\dotnet\sdk\2.1.300).
/// </summary>
public string ResolvedSdkDirectory;
/// <summary>
/// Path to global.json file that impacted resolution.
/// </summary>
public string GlobalJsonPath;
public void Initialize(Interop.hostfxr_resolve_sdk2_result_key_t key, string value)
{
switch (key)
{
case Interop.hostfxr_resolve_sdk2_result_key_t.resolved_sdk_dir:
ResolvedSdkDirectory = value;
break;
case Interop.hostfxr_resolve_sdk2_result_key_t.global_json_path:
GlobalJsonPath = value;
break;
}
}
}
public static Result ResolveSdk(
string dotnetExeDirectory,
string globalJsonStartDirectory,
bool disallowPrerelease = false)
{
var result = new Result();
var flags = disallowPrerelease ? Interop.hostfxr_resolve_sdk2_flags_t.disallow_prerelease : 0;
int errorCode = Interop.RunningOnWindows
? Interop.Windows.hostfxr_resolve_sdk2(dotnetExeDirectory, globalJsonStartDirectory, flags, result.Initialize)
: Interop.Unix.hostfxr_resolve_sdk2(dotnetExeDirectory, globalJsonStartDirectory, flags, result.Initialize);
Debug.Assert((errorCode == 0) == (result.ResolvedSdkDirectory != null));
return result;
}
private sealed class SdkList
{
public string[] Entries;
public void Initialize(int count, string[] entries)
{
entries = entries ?? Array.Empty<string>();
Debug.Assert(count == entries.Length);
Entries = entries;
}
}
public static string[] GetAvailableSdks(string dotnetExeDirectory)
{
var list = new SdkList();
int errorCode = Interop.RunningOnWindows
? Interop.Windows.hostfxr_get_available_sdks(dotnetExeDirectory, list.Initialize)
: Interop.Unix.hostfxr_get_available_sdks(dotnetExeDirectory, list.Initialize);
return list.Entries;
}
}
}

View file

@ -1,155 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
#if NET46
using Microsoft.VisualStudio.Setup.Configuration;
#endif
namespace Microsoft.DotNet.MSBuildSdkResolver
{
internal sealed class VSSettings
{
private readonly object _lock = new object();
private readonly string _settingsFilePath;
private readonly bool _disallowPrereleaseByDefault;
private FileInfo _settingsFile;
private bool _disallowPrerelease;
// In the product, this singleton is used. It must be safe to use in parallel on multiple threads.
// In tests, mock instances can be created with the test constructor below.
public static readonly VSSettings Ambient = new VSSettings();
private VSSettings()
{
#if NET46
if (!Interop.RunningOnWindows)
{
return;
}
string instanceId;
string installationVersion;
bool isPrerelease;
try
{
var configuration = new SetupConfiguration();
var instance = configuration.GetInstanceForCurrentProcess();
instanceId = instance.GetInstanceId();
installationVersion = instance.GetInstallationVersion();
isPrerelease = ((ISetupInstanceCatalog)instance).IsPrerelease();
}
catch (COMException)
{
return;
}
var version = Version.Parse(installationVersion);
_settingsFilePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Microsoft",
"VisualStudio",
version.Major + ".0_" + instanceId,
"sdk.txt");
_disallowPrereleaseByDefault = !isPrerelease;
_disallowPrerelease = _disallowPrereleaseByDefault;
#endif
}
// Test constructor
public VSSettings(string settingsFilePath, bool disallowPrereleaseByDefault)
{
_settingsFilePath = settingsFilePath;
_disallowPrereleaseByDefault = disallowPrereleaseByDefault;
_disallowPrerelease = _disallowPrereleaseByDefault;
}
public bool DisallowPrerelease()
{
if (_settingsFilePath != null)
{
Refresh();
}
return _disallowPrerelease;
}
private void Refresh()
{
Debug.Assert(_settingsFilePath != null);
var file = new FileInfo(_settingsFilePath);
// NB: All calls to Exists and LastWriteTimeUtc below will not hit the disk
// They will return data obtained during Refresh() here.
file.Refresh();
lock (_lock)
{
// File does not exist -> use default.
if (!file.Exists)
{
_disallowPrerelease = _disallowPrereleaseByDefault;
_settingsFile = file;
return;
}
// File has not changed -> reuse prior read.
if (_settingsFile?.Exists == true && file.LastWriteTimeUtc <= _settingsFile.LastWriteTimeUtc)
{
return;
}
// File has changed -> read from disk
// If we encounter an I/O exception, assume writer is in the process of updating file,
// ignore the exception, and use stale settings until the next resolution.
try
{
ReadFromDisk();
_settingsFile = file;
return;
}
catch (IOException) { }
catch (UnauthorizedAccessException) { }
}
}
private void ReadFromDisk()
{
using (var reader = new StreamReader(_settingsFilePath))
{
string line;
while ((line = reader.ReadLine()) != null)
{
int indexOfEquals = line.IndexOf('=');
if (indexOfEquals < 0 || indexOfEquals == (line.Length - 1))
{
continue;
}
string key = line.Substring(0, indexOfEquals).Trim();
string value = line.Substring(indexOfEquals + 1).Trim();
if (key.Equals("UsePreviews", StringComparison.OrdinalIgnoreCase)
&& bool.TryParse(value, out bool usePreviews))
{
_disallowPrerelease = !usePreviews;
return;
}
}
}
// File does not have UsePreviews entry -> use default
_disallowPrerelease = _disallowPrereleaseByDefault;
}
}
}

View file

@ -1,23 +0,0 @@

using System;
using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.DotNet.ToolPackage
{
internal class PackageLocation
{
public PackageLocation(
FilePath? nugetConfig = null,
DirectoryPath? rootConfigDirectory = null,
string[] additionalFeeds = null)
{
NugetConfig = nugetConfig;
RootConfigDirectory = rootConfigDirectory;
AdditionalFeeds = additionalFeeds ?? Array.Empty<string>();
}
public FilePath? NugetConfig { get; }
public DirectoryPath? RootConfigDirectory { get; }
public string[] AdditionalFeeds { get; }
}
}

View file

@ -1,36 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.DotNet.Cli.CommandLine;
using LocalizableStrings = Microsoft.DotNet.Tools.Restore.LocalizableStrings;
namespace Microsoft.DotNet.Cli
{
internal static class ToolCommandRestorePassThroughOptions
{
public static Option DisableParallelOption()
{
return Create.Option(
"--disable-parallel",
LocalizableStrings.CmdDisableParallelOptionDescription,
Accept.NoArguments().ForwardAs("--disable-parallel"));
}
public static Option NoCacheOption()
{
return Create.Option(
"--no-cache",
LocalizableStrings.CmdNoCacheOptionDescription,
Accept.NoArguments().ForwardAs("--no-cache"));
}
public static Option IgnoreFailedSourcesOption()
{
return Create.Option(
"--ignore-failed-sources",
LocalizableStrings.CmdIgnoreFailedSourcesOptionDescription,
Accept.NoArguments().ForwardAs("--ignore-failed-sources"));
}
}
}