All Projects → novotnyllc → Msbuildsdkextras

novotnyllc / Msbuildsdkextras

Licence: mit
Extra properties for MSBuild SDK projects

Projects that are alternatives of or similar to Msbuildsdkextras

Nlog
NLog - Advanced and Structured Logging for Various .NET Platforms
Stars: ✭ 5,296 (+1738.89%)
Mutual labels:  xamarin, uwp, netcore
Xam.plugin.webview
Xamarin Plugin for a HybridWebView in PCL projects.
Stars: ✭ 132 (-54.17%)
Mutual labels:  pcl, xamarin, uwp
Microsoft Authentication Library For Dotnet
Microsoft Authentication Library (MSAL) for .NET
Stars: ✭ 746 (+159.03%)
Mutual labels:  xamarin, uwp, netcore
Connectivityplugin
Connectivity Plugin for Xamarin and Windows
Stars: ✭ 253 (-12.15%)
Mutual labels:  pcl, xamarin, uwp
Megaapiclient
MegaApiClient is a C# .Net library to access http://mega.co.nz / http://mega.nz cloud storage and file hosting service.
Stars: ✭ 151 (-47.57%)
Mutual labels:  xamarin, uwp, netcore
Portable-WebDAV-Library
Moved to codeberg.org - https://codeberg.org/DecaTec/Portable-WebDAV-Library - The Portable WebDAV Library is a strongly typed, async WebDAV client library which is fully compliant to RFC 4918, RFC 4331 and "Additional WebDAV Collection Properties". It is implemented as .NETStandard 1.1 library in oder to be used on any platform supporting .NETS…
Stars: ✭ 45 (-84.37%)
Mutual labels:  xamarin, uwp, netcore
Arcgis Runtime Samples Dotnet
Sample code for ArcGIS Runtime SDK for .NET – UWP, WPF, Xamarin.Android, Xamarin.iOS, and Xamarin.Forms
Stars: ✭ 274 (-4.86%)
Mutual labels:  xamarin, uwp
vs-material-icons-generator
This plugin will help you to set material design icons to your Xamarin projects In Visual Studio.
Stars: ✭ 50 (-82.64%)
Mutual labels:  xamarin, uwp
ScreenshotPlugin
A simple Screenshot plugin for Xamarin and Windows to get and save screenshot in yours apps.
Stars: ✭ 32 (-88.89%)
Mutual labels:  xamarin, pcl
WeakEventListener
The WeakEventListener allows the owner to be garbage collected if its only remaining link is an event handler.
Stars: ✭ 25 (-91.32%)
Mutual labels:  xamarin, uwp
XPlat-Windows-APIs
UWP style APIs cross-platform with .NET!
Stars: ✭ 31 (-89.24%)
Mutual labels:  xamarin, uwp
XamFormsMvxTemplate
A Visual Studio 2017 template for projects based on Xamarin.Forms 3.3 and MvvmCross 6.2
Stars: ✭ 27 (-90.62%)
Mutual labels:  xamarin, uwp
Microcharts
Create cross-platform (Xamarin, Windows, ...) simple charts.
Stars: ✭ 1,742 (+504.86%)
Mutual labels:  xamarin, uwp
XamarinClipboardPlugin
Cross Platform Clipboard access for Xamarin
Stars: ✭ 24 (-91.67%)
Mutual labels:  xamarin, pcl
Vaser
Vaser is a powerful high performance event based network engine library for C# .Net. It’s possible to start multiple servers in one program and use the same network code for all servers. In the network communication are all strings are omitted, instead it is based on a unique binary identifier, which the CPU and memory relieves massively.
Stars: ✭ 23 (-92.01%)
Mutual labels:  xamarin, netcore
PCLExt.FileStorage
Portable Storage APIs
Stars: ✭ 35 (-87.85%)
Mutual labels:  xamarin, uwp
ably-dotnet
.NET, Xamarin and Mono client library SDK for Ably realtime messaging service
Stars: ✭ 32 (-88.89%)
Mutual labels:  xamarin, uwp
dotnet
.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
Stars: ✭ 865 (+200.35%)
Mutual labels:  uwp, netcore
Uno.Themes
This library is designed to help you use the material design system with the Uno Platform
Stars: ✭ 112 (-61.11%)
Mutual labels:  xamarin, uwp
Toast
To use it in PCL or .NetStandard projects write this line of code : CrossToastPopUp.Current.ShowToastMessage("Message");
Stars: ✭ 51 (-82.29%)
Mutual labels:  xamarin, uwp

MSBuild.Sdk.Extras

Summary

This package contains a few extra extensions to the SDK-style projects that are currently not available in Microsoft.NET.Sdk SDK. This feature is tracked in dotnet/sdk#491 and many of the scenarios are on the roadmap for .NET 6.

The primary goal of this project is to enable multi-targeting without you having to enter in tons of properties within your csproj, vbproj, fsproj, thus keeping it nice and clean.

See the blog post for more information.

Supported .NET Core SDK Versions

Important: 3.x of the Extras requires the .NET 5 SDK or later. The SDK can build previous targets, like netcoreapp3.1. The extras 2.x supports SDK 2.x and 3.x.

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 blogs 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 for creating these using the Extras easily.

Package Name: MSBuild.Sdk.Extras

Stable: MSBuild.Sdk.Extras

CI Feed: MSBuild.Sdk.Extras package in MSBuildSdkExtras feed in Azure Artifacts https://pkgs.dev.azure.com/clairernovotny/GitBuilds/_packaging/MSBuildSdkExtras/nuget/v3/index.json

Getting started (VS 15.6+)

Visual Studio 2017 Update 6 (aka v15.6) includes support for SDK's resolved from NuGet, which is required for this to work. VS 2019 is recommended.

Using the SDK

  1. Create a new project

    • .NET Core console app or .NET Standard class library.
    • With your existing SDK-style project.
    • With the templates in the repo's TestProjects folder.
  2. Replace Microsoft.NET.Sdk with MSBuild.Sdk.Extras to the project's top-level Sdk attribute.

  3. You have to tell MSBuild that the Sdk should resolve from NuGet by

    • Adding a global.json containing the Sdk name and version.
    • Appending a version info to the Sdk attribute value.
  4. Then you can edit the TargetFramework to a different TFM, or you can rename TargetFramework to TargetFrameworks and specify multiple TFM's with a ; separator.

The final project should look like this:

<Project Sdk="MSBuild.Sdk.Extras">
  <PropertyGroup>
    <TargetFrameworks>net46;uap10.0.19041;tizen8.0</TargetFrameworks>
  </PropertyGroup>
</Project>

The .NET 5 SDK is the latest and has more support for desktop workloads. It's strongly recommended to use that SDK, even to build older targets. If you are using MsBuild.Sdk.Extras version 2 or above, use the .NET Core 3.1 SDK at a minimum. You can still target previous versions of .NET Core.

{
  "msbuild-sdks": {
    "MSBuild.Sdk.Extras": "3.0.22"
  }
}

Above the sdk section indicates use the .NET Core 3 preview to build, the msbuild-sdks indicates the NuGet package to include.

Then, all of your project files, from that directory forward, uses the version from the global.json file. This would be a preferred solution for all the projects in your solution.

Then again, you might want to override the version for just one project OR if you have only one project in your solution (without adding global.json), you can do so like this:

<Project Sdk="MSBuild.Sdk.Extras/3.0.22">
  <PropertyGroup>
    <TargetFrameworks>net46;uap10.0.19041;tizen8.0</TargetFrameworks>
  </PropertyGroup>
</Project>

That's it. You do not need to specify the UWP or Tizen meta-packages as they'll be automatically included. After that, you can use the Restore, Build, Pack targets to restore packages, build the project and create NuGet packages. E.g.: msbuild /t:Pack ...

Important to Note

  • It will only work with an IDE that uses the desktop msbuild (i.e. Visual Studio) and the target Platform SDKs which are not cross platform.
  • When using JetBrains Rider, you will need to point to your desktop MSBuild in your settings (Settings > Build, execution, deployment > Use MSBuild Version)
  • When building from the CLI, you must use MSBuild.exe. dotnet build will not work for most project types.
  • It might work in Visual Studio Code, but you have to configure build tasks in launch.json to use desktop msbuild to build.
  • You must install the tools of the platforms you intend to build. For Xamarin, that means the Xamarin Workload; for UWP install those tools as well.

More information on how SDK's are resolved can be found here.

Creating Per-RuntimeIdentifier packages

You'll need to perform a few steps:

  1. Make sure to use TargetFrameworks instead of TargetFramework, even if you're only building a single target framework. I am piggy-backing off of its looping capabilities.
  2. Set the RuntimeIdentifiers property to valid RID's (full list), separated by a semi-colon (<RuntimeIdentifiers>win;unix</RuntimeIdentifiers>).
  3. For the TFM's that you want want to build separately, set the ExtrasBuildEachRuntimeIdentifier property to true.

When you're done, you should be able to run build/pack and it'll produce a NuGet package.

Notes:

  • You must use the Sdk="MSBuild.Sdk.Extras" method for this. Using PackageReference is unsupported for this scenario.
  • While the Visual Studio context won't show each RID, it'll build for each.
  • The Extras defines a preprocessor 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.
  • The default path for per-RID output assemblies and symbols in NuGet package is runtimes/<RuntimeIdentifier>/lib/<TargetFramework>.
  • RuntimeIdentifiers can be set per-TargetFramework using a condition on the property. This lets you have multiple TFM's, but only some of which have RID's.

Reference Assemblies

You will likely need to create reference assemblies to simplify development and consumption of your libraries with complex flavor (TargetFramework × RuntimeIdentifier) matrix. Reference assemblies are packed into ref/<TargetFramework> folder. Please see my two blogs articles for details.

Packing additional contents

If you need to add native assets into runtimes, the easiest way is to use:

<None Include="path/to/native.dll" PackagePath="runtimes/<rid>/native" Pack="true" />

Overriding content paths in output package

Minimal example to pack output assemblies and symbols to tools (instead of runtimes) subfolders.

<PropertyGroup>
  <ExtrasIncludeDefaultProjectBuildOutputInPackTarget>IncludeDefaultProjectBuildOutputInPack</ExtrasIncludeDefaultProjectBuildOutputInPackTarget>
</PropertyGroup>

<Target Name="IncludeDefaultProjectBuildOutputInPack">
  <ItemGroup>
    <None Include="@(RidSpecificOutput)" PackagePath="tools/%(TargetFramework)/%(Rid)" Pack="true" />
  </ItemGroup>
</Target>

For advanced options, see ClasslibPack* SDK tests and RIDs.targets file.

Migrate from the old way (VS pre-15.6)

For those who are using in a PackageReference style, you can't do that with v2.0+ of this package. So update VS to 15.6+ and manually upgrade your projects as shown below:

  1. The same as above, replace the Sdk attribute's value.
  2. Remove the workaround import specified with the old way. The import property should be MSBuildSdkExtrasTargets.
  3. Do a trial build and then compare your project with the templates in the repo's TestProjects folder to troubleshoot any issues if you encounter them.
  4. Please file a issue.

Your project diff:

- <Project Sdk="Microsoft.NET.Sdk">
+ <Project Sdk="MSBuild.Sdk.Extras">
  <!-- OTHER PROPERTIES -->
  <PropertyGroup>
    <TargetFrameworks>net46;uap10.0.16299;tizen40</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup>
-    <PackageReference Include="MSBuild.Sdk.Extras" Version="1.6.0" PrivateAssets="All"/>
  <!-- OTHER PACKAGES/INCLUDES -->
  </ItemGroup>

-  <Import Project="$(MSBuildSdkExtrasTargets)" Condition="Exists('$(MSBuildSdkExtrasTargets)')"/>
  <!-- OTHER IMPORTS -->
</Project>
- PackageReference style
+ SDK style

Note: The SDK-style project now works on Visual Studio for Mac.

Release Notes

1.6.0

  • A few properties have been changed, and the help is provided as a warning to use the new property names.

    Old Property New Property/Behaviour
    SuppressWarnIfOldSdkPack ExtrasIgnoreOldSdkWarning
    ExtrasImplicitPlatformPackageDisabled DisableImplicitFrameworkReferences + TargetFramework condition
    EmbeddedResourceGeneratorVisibilityIsInternal opposite of ExtrasEmbeddedResourceGeneratedCodeIsPublic
  • Support for WPF and Windows Forms requires an opt-in property to enable: Set ExtrasEnableWpfProjectSetup/ExtrasEnableWinFormsProjectSetup to true to include required references and default items. Note in .NET Core 3.0 these have been replaced by UseWPF/UseWindowsForms.

Single or multi-targeting

Once this package is configured, you can now use any supported TFM in your TargetFramework or TargetFrameworks element. The supported TFM families are:

  • netstandard (.NET Standard)
  • netcoreapp (.NET Core App)
  • net (.NET 5+ & .NET Framework)
  • net35-client/net40-client (.NET Framework legacy Client profile)
  • wpa (Windows Phone App 8.1)
  • win (Windows 8 / 8.1)
  • uap (Windows 10 / UWP)
  • wp (Windows Phone Silverlight, WP7+)
  • sl (Silverlight 4+)
  • tizen (Tizen 3+)
  • xamarin.android
  • xamarin.ios
  • xamarin.mac
  • xamarin.watchos
  • xamarin.tvos
  • portableNN-/portable- (legacy PCL profiles like portable-net45+win8+wpa81+wp8)

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.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].