-
Notifications
You must be signed in to change notification settings - Fork 40
Add SDK package for generating global CLI tool shims #660
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
Changes from all commits
41bfe89
119a3d4
a467a24
4a1ee4e
bde5466
a1ff4a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
<ItemGroup> | ||
<Projects Include="$(MSBuildThisFileDirectory)..\..\src\Internal.AspNetCore.Sdk\Internal.AspNetCore.Sdk.csproj" /> | ||
<Projects Include="$(MSBuildThisFileDirectory)..\..\src\ApiCheck.Console\ApiCheck.Console.csproj" /> | ||
<Projects Include="$(MSBuildThisFileDirectory)..\..\src\Microsoft.DotNet.GlobalTools.Sdk\Microsoft.DotNet.GlobalTools.Sdk.csproj" /> | ||
</ItemGroup> | ||
|
||
<MSBuild Projects="@(Projects)" | ||
|
@@ -13,7 +14,30 @@ | |
BuildInParallel="true" | ||
RemoveProperties="PublishDir" /> | ||
|
||
<Copy SourceFiles="module.props" DestinationFolder="$(PublishDir)" /> | ||
<PropertyGroup> | ||
<!-- | ||
This is a workaround for https://github.com/Microsoft/msbuild/issues/2914. | ||
Currently, the only way to configure the NuGetSdkResolver is with NuGet.config, which is not generally used in aspnet org projects. | ||
This project is restored so that it pre-populates the NuGet cache with SDK packages. | ||
--> | ||
<BundledPackageRestorerContent> | ||
<![CDATA[ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Internal.AspNetCore.Sdk" Version="$(Version)" /> | ||
<PackageReference Include="Microsoft.DotNet.GlobalTools.Sdk" Version="$(Version)" /> | ||
</ItemGroup> | ||
</Project> | ||
]]> | ||
</BundledPackageRestorerContent> | ||
</PropertyGroup> | ||
|
||
<WriteLinesToFile File="$(PublishDir)BundledPackageRestorer.csproj" Lines="$(BundledPackageRestorerContent)" Overwrite="true" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sad 👏 |
||
<Copy SourceFiles="module.props;module.targets" DestinationFolder="$(PublishDir)" /> | ||
</Target> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project> | ||
<PropertyGroup Condition="'$(DisableDefaultTargets)' != 'true'"> | ||
<PrepareDependsOn>PreinstallBundledPackages;$(PrepareDependsOn)</PrepareDependsOn> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
This is a workaround for https://github.com/Microsoft/msbuild/issues/2914. | ||
This pre-populates the NuGet cache with bundled packages. | ||
--> | ||
<Target Name="PreinstallBundledPackages"> | ||
<MSBuild Targets="Restore" | ||
Projects="$(MSBuildThisFileDirectory)BundledPackageRestorer.csproj" | ||
Properties="RestoreSources=$(KoreBuildBundledPackageFolder)" /> | ||
</Target> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project> | ||
|
||
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" /> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<NuspecFile>$(MSBuildThisFileDirectory)$(MSBuildProjectName).nuspec</NuspecFile> | ||
<Serviceable>false</Serviceable> | ||
<NoPackageAnalysis>true</NoPackageAnalysis> | ||
<IncludeBuildOutput>false</IncludeBuildOutput> | ||
<IncludeSource>false</IncludeSource> | ||
<IncludeSymbols>false</IncludeSymbols> | ||
</PropertyGroup> | ||
|
||
<Target Name="SetPackageProperties" BeforeTargets="GenerateNuspec"> | ||
<PropertyGroup> | ||
<NuspecProperties>$(NuspecProperties);id=$(PackageId)</NuspecProperties> | ||
<NuspecProperties>$(NuspecProperties);version=$(PackageVersion)</NuspecProperties> | ||
<NuspecProperties>$(NuspecProperties);copyright=$(Copyright)</NuspecProperties> | ||
</PropertyGroup> | ||
</Target> | ||
|
||
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" /> | ||
|
||
<Target Name="Compile" /> | ||
<Target Name="CopyFilesToOutputDirectory" /> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> | ||
<metadata> | ||
<id>$id$</id> | ||
<version>$version$</version> | ||
<authors>Microsoft</authors> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<description>Provides additional support to .NET Core teams producing global CLI tools. This package is only intended for internal Microsoft use.</description> | ||
<copyright>$copyright$</copyright> | ||
<packageTypes> | ||
<!-- This project needs to be MSBuildSdk because its targets need to influence the way /t:Restore works --> | ||
<packageType name="MSBuildSdk" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does Razor Sdk need one of these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depends. Do you expect users to reference razor as a PackageReference or only as an Sdk? If you add this, UI tooling in VS for PackageReference will break. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preferably both. We use it as a PackageReference in other repos in aspnet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If NuGet UI tooling wasn't a concern, I would say you should add this to your .nuspec <packageTypes>
<packageType name="Dependency" /> <!-- PackageReference usage -->
<packageType name="MSBuildSdk" /> <!-- Sdk usage -->
</packageTypes> But that might be dangerous because the NuGet team is thinking of breaking packages with multiple types. See NuGet/Home#6298 and NuGet/Home#6484 for context. |
||
</packageTypes> | ||
</metadata> | ||
<files> | ||
<file src="_._" target="lib/netstandard1.0/_._" /> | ||
<file src="sdk\**\*" target="sdk/" /> | ||
</files> | ||
</package> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Microsoft.DotNet.GlobalTools.Sdk | ||
================================ | ||
|
||
Provides additional support to .NET Core teams producing global CLI tools. This package is only intended for internal Microsoft use. | ||
|
||
## Usage | ||
Projects that need to bundle and sign the global CLI tool shim should add this to their .csproj file. This will include files in the .nupkg. | ||
|
||
```xml | ||
<!-- In MyTool.csproj --> | ||
<Project> | ||
<Sdk Name="Microsoft.NET.Sdk" /> | ||
<Sdk Name="Microsoft.DotNet.GlobalTools.Sdk" /> | ||
|
||
<PropertyGroup> | ||
<PackAsTool>true</PackAsTool> | ||
<GenerateToolShims>true</GenerateToolShims> | ||
</PropertyGroup> | ||
</Project> | ||
``` | ||
|
||
```js | ||
// in global.json | ||
{ | ||
"msbuild-sdks": { | ||
"Microsoft.DotNet.GlobalTools.Sdk": "2.1.0-rtm-12345" | ||
} | ||
} | ||
``` | ||
|
||
### Additional options | ||
|
||
#### `GenerateToolShims` (property) | ||
|
||
A boolean flag. When `true`, tool shims will be generated for each RID listed in `GeneratedShimRuntimeIdentifiers` and included in the .nupkg. | ||
|
||
Default value = `false` | ||
|
||
#### `GeneratedShimRuntimeIdentifiers` (property) | ||
|
||
A semi-colon separate list of RIDs for which to generate and pack the shim. | ||
|
||
Default value = `win-x86;win-x64;osx-x64` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<PropertyGroup> | ||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(DisableImplicitFrameworkReferences)' != 'true'"> | ||
<PackageReference Include="Microsoft.NETCore.DotNetAppHost" Version="$(MicrosoftNETCoreDotNetAppHostImplicitPackageVersion)" PrivateAssets="All" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<PropertyGroup> | ||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | ||
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);GetDotNetToolShimPackageContent</TargetsForTfmSpecificContentInPackage> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<!-- | ||
Define the package version of Microsoft.NETCore.DotNetAppHost to match the shared runtime version | ||
--> | ||
<MicrosoftNETCoreDotNetAppHostImplicitPackageVersion Condition="'$(MicrosoftNETCoreDotNetAppHostImplicitPackageVersion)' == ''">$(RuntimeFrameworkVersion)</MicrosoftNETCoreDotNetAppHostImplicitPackageVersion> | ||
|
||
<!-- | ||
Only generate shims for these platforms. | ||
--> | ||
<GeneratedShimRuntimeIdentifiers Condition="'$(GeneratedShimRuntimeIdentifiers)' == ''">win-x86;win-x64;osx-x64</GeneratedShimRuntimeIdentifiers> | ||
|
||
<!-- | ||
Define runtime identifiers to NuGet will restore the apphost for that RID. | ||
--> | ||
<RuntimeIdentifiers>$(RuntimeIdentifiers);$(GeneratedShimRuntimeIdentifiers)</RuntimeIdentifiers> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
************************************************************ | ||
Target: GetDotNetToolShimPackageContent | ||
|
||
Gets package content items for the global shim, without building anything. | ||
************************************************************ | ||
--> | ||
<Target Name="GetDotNetToolShimPackageContent" DependsOnTargets="_ComputeGeneratedDotNetToolShims"> | ||
<ItemGroup> | ||
<!-- Add the file to the package --> | ||
<TfmSpecificPackageFile Include="@(GeneratedDotNetToolShim)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<!-- | ||
************************************************************ | ||
Target: GenerateDotNetToolShims | ||
|
||
Generates the dotnettool shims | ||
************************************************************ | ||
--> | ||
<Target Name="GenerateDotNetToolShims" | ||
DependsOnTargets="_ComputeGeneratedDotNetToolShims;_CoreGenerateDotNetToolShim" | ||
BeforeTargets="CoreCompile" /> | ||
|
||
<Target Name="_ComputeGeneratedDotNetToolShims"> | ||
<PropertyGroup> | ||
<_NormalizedPackageVersion>$(PackageVersion)</_NormalizedPackageVersion> | ||
<_NormalizedPackageVersion Condition="$(_NormalizedPackageVersion.Contains('+'))">$(_NormalizedPackageVersion.Substring($(_NormalizedPackageVersion.IndexOf('+'))))</_NormalizedPackageVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<_ShimRids Include="$(GeneratedShimRuntimeIdentifiers)" AppHostFileName="$(AssemblyName)" /> | ||
<_ShimRids Update="%(_ShimRids.Identity)" AppHostFileName="$(AssemblyName).exe" Condition="$([System.String]::new('%(_ShimRids.Identity)').StartsWith('win'))" /> | ||
|
||
<GeneratedDotNetToolShim Condition="'%(_ShimRids.Identity)' != ''" Include="$(IntermediateOutputPath)shims/%(_ShimRids.Identity)/%(_ShimRids.AppHostFileName)"> | ||
<RuntimeIdentifier>%(_ShimRids.Identity)</RuntimeIdentifier> | ||
<OutputDir>$(IntermediateOutputPath)shims/%(_ShimRids.Identity)/</OutputDir> | ||
<PackagePath>tools/$(TargetFramework)/any/shims/%(_ShimRids.Identity)/</PackagePath> | ||
<RelativeAppBinaryFilePath>.store/$(PackageId.ToLowerInvariant())/$(_NormalizedPackageVersion)/$(PackageId.ToLowerInvariant())/$(_NormalizedPackageVersion)/tools/$(TargetFramework)/any/$(TargetFileName)</RelativeAppBinaryFilePath> | ||
</GeneratedDotNetToolShim> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<!-- This task is defined in Microsoft.NET.Sdk --> | ||
<UsingTask TaskName="EmbedAppNameInHost" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" /> | ||
|
||
<Target Name="_CoreGenerateDotNetToolShim" | ||
DependsOnTargets="_ComputeGeneratedDotNetToolShims" | ||
Inputs="$(MSBuildAllProjects);$(ProjectAssetsFile)" | ||
Outputs="@(GeneratedDotNetToolShim)"> | ||
|
||
<MSBuild | ||
Targets="_CoreGenerateDotNetToolShimForRid" | ||
Projects="$(MSBuildProjectFullPath)" | ||
Properties=" | ||
TargetFramework=$(TargetFramework); | ||
RuntimeIdentifier=%(GeneratedDotNetToolShim.RuntimeIdentifier); | ||
_ShimRelativeAppBinaryFilePath=%(GeneratedDotNetToolShim.RelativeAppBinaryFilePath); | ||
_ShimOutputDir=%(GeneratedDotNetToolShim.OutputDir)" | ||
Condition="'%(GeneratedDotNetToolShim.Identity)' != ''" /> | ||
</Target> | ||
|
||
<Target Name="_CoreGenerateDotNetToolShimForRid" DependsOnTargets="ResolvePackageAssets"> | ||
<ItemGroup> | ||
<NativeRestoredAppHostNETCore Include="@(NativeCopyLocalItems)" | ||
Condition="'%(NativeCopyLocalItems.FileName)%(NativeCopyLocalItems.Extension)' == '$(_DotNetAppHostExecutableName)'"/> | ||
</ItemGroup> | ||
|
||
<NETSdkError Condition="'@(NativeRestoredAppHostNETCore->Count())' > 1" | ||
ResourceName="MultipleFilesResolved" | ||
FormatArguments="$(_DotNetAppHostExecutableName)" /> | ||
|
||
<EmbedAppNameInHost AppHostSourcePath="@(NativeRestoredAppHostNETCore)" | ||
AppHostDestinationDirectoryPath="$(_ShimOutputDir)" | ||
AppBinaryName="$(_ShimRelativeAppBinaryFilePath)"/> | ||
</Target> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<PropertyGroup> | ||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | ||
</PropertyGroup> | ||
|
||
<Import | ||
Project="Microsoft.DotNetTool.ShimGeneration.props" | ||
Condition="'$(PackAsTool)' == 'true' AND '$(GenerateToolShims)' == 'true' AND '$(TargetFramework)' != ''" /> | ||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need
RestoreSources
or does it pick the one via Directory.Build.props?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's set in the PreinstallBundledPackages target (see below). We can't set it here since the path will be machine-specific.