From 2d908cb264a2eda1eb2fd535426aa159c16917a8 Mon Sep 17 00:00:00 2001 From: Oren Novotny Date: Tue, 10 Jul 2018 13:09:14 -0400 Subject: [PATCH 1/6] Build each RID on the inner loop --- Source/MSBuild.Sdk.Extras/Build/RIDs.targets | 44 +++++++++++++++++++ Source/MSBuild.Sdk.Extras/Sdk/Sdk.targets | 5 ++- .../ClasslibraryAsSdk.csproj | 5 ++- 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 Source/MSBuild.Sdk.Extras/Build/RIDs.targets diff --git a/Source/MSBuild.Sdk.Extras/Build/RIDs.targets b/Source/MSBuild.Sdk.Extras/Build/RIDs.targets new file mode 100644 index 0000000..ec4b3e6 --- /dev/null +++ b/Source/MSBuild.Sdk.Extras/Build/RIDs.targets @@ -0,0 +1,44 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + + + + + + false + + + + <_SdkRuntimeIds Include="$(RuntimeIdentifiers)" Condition="'$(RuntimeIdentifiers)' != '' and '$(ExtrasBuildEachRuntimeIdentifier)' == 'true' " TargetFramework="$(TargetFramework)" /> + + <_SdkRuntimeId Include="@(_SdkRuntimeIds->'%(TargetFramework)')" Rid="%(_SdkRuntimeIds.Identity)" /> + <_SdkRuntimeId Include="$(TargetFramework)" Condition="'$(ExtrasBuildEachRuntimeIdentifier)' == 'false'" /> + + + + + + + + <_TargetFramework Include="$(TargetFrameworks)" /> + + + + + + + + <_InnerBuildProjects Include="$(MSBuildProjectFile)"> + TargetFramework=%(_SdkTargetsWithRids.Identity);RuntimeIdentifier=%(_SdkTargetsWithRids.Rid) + TargetFramework=%(_SdkTargetsWithRids.Identity) + + + + + + \ No newline at end of file diff --git a/Source/MSBuild.Sdk.Extras/Sdk/Sdk.targets b/Source/MSBuild.Sdk.Extras/Sdk/Sdk.targets index 132f679..800435d 100644 --- a/Source/MSBuild.Sdk.Extras/Sdk/Sdk.targets +++ b/Source/MSBuild.Sdk.Extras/Sdk/Sdk.targets @@ -1,4 +1,4 @@ - + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) @@ -14,4 +14,7 @@ + + + \ No newline at end of file diff --git a/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj b/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj index 3c95ae1..66c2a3b 100644 --- a/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj +++ b/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj @@ -5,8 +5,9 @@ - uap10.0;uap10.0.16299;monoandroid70;xamarin.ios10;xamarin.mac20;tizen40 - false + netstandard2.0;uap10.0;uap10.0.16299;monoandroid70;xamarin.ios10;xamarin.mac20;tizen40 + win;unix + true From 16cfe4000f841760c4b8f9579fd136738d41f6b1 Mon Sep 17 00:00:00 2001 From: Oren Novotny Date: Tue, 10 Jul 2018 14:02:00 -0400 Subject: [PATCH 2/6] Add in RID defines --- Source/MSBuild.Sdk.Extras/Build/Platforms.targets | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/MSBuild.Sdk.Extras/Build/Platforms.targets b/Source/MSBuild.Sdk.Extras/Build/Platforms.targets index 1beeb1c..8ed4e2f 100644 --- a/Source/MSBuild.Sdk.Extras/Build/Platforms.targets +++ b/Source/MSBuild.Sdk.Extras/Build/Platforms.targets @@ -21,6 +21,7 @@ $(TargetFrameworkIdentifier.TrimStart('.').Replace('.','_').ToUpperInvariant()) $(TargetFramework.Replace('.','_').Replace('-','_').ToUpperInvariant()) + <_SdkRuntimeIdentifierDefine Condition="'$(RuntimeIdentifier)' != ''">$(RuntimeIdentifier.Replace('.','_').Replace('-','_').ToUpperInvariant()) @@ -30,13 +31,13 @@ - $(DefineConstants); - $(DefineConstants)$(_SdkImplicitFrameworkProfileDefine) + $(DefineConstants);$(_SdkImplicitFrameworkProfileDefine) + $(DefineConstants);$(_SdkRuntimeIdentifierDefine) - $(FinalDefineConstants), - $(FinalDefineConstants)$(_SdkImplicitFrameworkProfileDefine)=-1 + $(FinalDefineConstants),$(_SdkImplicitFrameworkProfileDefine)=-1 + $(FinalDefineConstants),$(_SdkRuntimeIdentifierDefine)=-1 From 9a3983d7f578ea7520f54ed6a0f42f8fa647aa84 Mon Sep 17 00:00:00 2001 From: Oren Novotny Date: Tue, 10 Jul 2018 15:45:32 -0400 Subject: [PATCH 3/6] Pack files in correct location --- Source/MSBuild.Sdk.Extras/Build/RIDs.targets | 150 +++++++++++++++++- .../ClasslibraryAsSdk.csproj | 9 +- 2 files changed, 157 insertions(+), 2 deletions(-) diff --git a/Source/MSBuild.Sdk.Extras/Build/RIDs.targets b/Source/MSBuild.Sdk.Extras/Build/RIDs.targets index ec4b3e6..572844a 100644 --- a/Source/MSBuild.Sdk.Extras/Build/RIDs.targets +++ b/Source/MSBuild.Sdk.Extras/Build/RIDs.targets @@ -39,6 +39,154 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_TargetPathsToSymbolsWithTfm Update="@(_TargetPathsToSymbolsWithTfm)" Rid="$(RuntimeIdentifier)" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj b/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj index 66c2a3b..fca76ef 100644 --- a/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj +++ b/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj @@ -5,12 +5,19 @@ - netstandard2.0;uap10.0;uap10.0.16299;monoandroid70;xamarin.ios10;xamarin.mac20;tizen40 + + netstandard2.0;net46 win;unix true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + + + From 2bc5d2261c4389b867ebb929a6df1ce81422c229 Mon Sep 17 00:00:00 2001 From: Oren Novotny Date: Tue, 10 Jul 2018 15:48:44 -0400 Subject: [PATCH 4/6] include docs --- Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj b/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj index fca76ef..d8ed57e 100644 --- a/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj +++ b/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj @@ -10,7 +10,7 @@ win;unix true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - + true From a9392200792475200510e3ff55cca1c15fe2943a Mon Sep 17 00:00:00 2001 From: Oren Novotny Date: Tue, 10 Jul 2018 15:52:58 -0400 Subject: [PATCH 5/6] Add rest of TFMs --- Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj b/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj index d8ed57e..5d54c19 100644 --- a/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj +++ b/Tests/ClasslibraryAsSdk/ClasslibraryAsSdk.csproj @@ -5,10 +5,9 @@ - - netstandard2.0;net46 + netstandard2.0;net46;uap10.0;uap10.0.16299;monoandroid70;xamarin.ios10;xamarin.mac20;tizen40 win;unix - true + true $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb true From 0504810fbf99eee797fd633f7463c3c3eb5b7206 Mon Sep 17 00:00:00 2001 From: Oren Novotny Date: Tue, 10 Jul 2018 16:19:06 -0400 Subject: [PATCH 6/6] update docs --- README.md | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index af05cc1..2412be2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MSBuild.Sdk.Extras +# MSBuild.Sdk.Extras ## Summary @@ -8,7 +8,21 @@ The primary goal of this project is to enable multi-targeting without you having See the [blog post](https://oren.codes/2017/01/04/multi-targeting-the-world-a-single-project-to-rule-them-all) for more information. -### Package Name: `MSBuild.Sdk.Extras` +## Advanced Scenarios + +This package also enables advanced library scenarios, allowing you to create reference assemblies and per-RuntimeIdentifier targets. + +### Reference Assemblies + +Reference Assemblies useful in a few scenarios. Please see my [two](https://oren.codes/2018/07/09/create-and-pack-reference-assemblies-made-easy/) [blogs](https://oren.codes/2018/07/03/create-and-pack-reference-assemblies/) for more details. + +### Per-RuntimeIdentifier + +In some cases involving native interop, it may be necessary to have different runtime versions. NuGet has supported this for a while if you use `PackageReference` by way of its `runtimes` folder in combination with a Reference Assembly. Creating and packing these were manual though. + +See [below](#rids) for creating these using the Extras easily. + +## Package Name: `MSBuild.Sdk.Extras` [![MSBuild.Sdk.Extras](https://img.shields.io/nuget/v/MSBuild.Sdk.Extras.svg)](https://nuget.org/packages/MSBuild.Sdk.Extras) [![MSBuild.Sdk.Extras](https://img.shields.io/myget/msbuildsdkextras/v/MSBuild.Sdk.Extras.svg)](https://myget.org/feed/msbuildsdkextras/package/nuget/MSBuild.Sdk.Extras) @@ -152,3 +166,23 @@ Once this package is configured, you can now use any supported TFM in your `Targ For legacy PCL profiles, the order of the TFM's in the list does not matter but the profile must be an exact match to one of the known profiles. If it's not, you'll get a compile error saying it's unknown. You can see the full list of known profiles here: [Portable Library Profiles by Stephen Cleary](https://portablelibraryprofiles.stephencleary.com/). If you try to use a framework that you don't have tools installed for, you'll get an error as well saying to check the tools. In some cases this might mean installing an older version of Visual Studio IDE (_like 2015_) to ensure that the necessary targets are installed on the machine. + +### Creating Per-RuntimeIdentifier packages + +You'll need a few things + +1. Make sure to use `TargetFrameworks` instead of `TargetFramework`, even if you're only building a single target framework. We are piggy-backing off of it's looping capabilities. +2. Set the `RuntimeIdentifiers` property to [valid RID's](https://docs.microsoft.com/en-us/dotnet/core/rid-catalog) ([full list](https://github.com/dotnet/corefx/blob/master/pkg/Microsoft.NETCore.Platforms/runtime.json)), separated by a semi-colon. (`win;unix`). These can be set per TFM using a condition on the property. This lets you have multiple TFM's, but only some of which have RID's. +3. For the TFM's that you want want to build separately, set the property `ExtrasBuildEachRuntimeIdentifier` to `true`. + +While the Visual Studio context won't show each RID, it'll build for each. The Extras defines a symbol for each RID for use (`win-x86` would be `WIN_X86` and `centos.7-x64` would be `CENTOS_7_X64`). Dots and dashes become underbars. + +You will also need a Reference Assembly for the `ref` folder. Please see my [two](https://oren.codes/2018/07/09/create-and-pack-reference-assemblies-made-easy/) [blogs](https://oren.codes/2018/07/03/create-and-pack-reference-assemblies/) articles for details. + +When you're done, you should be able to build/pack these and it'll create a NuGet package. Your per-RID targets will be in `runtimes//lib/` and the Reference Assembly will be in `ref/`. + +If you need to add native assets into runtimes, the easiest way is to use: + +`` + + \ No newline at end of file