Create and pack reference assemblies (made easy)
Last week I blogged about reference assemblies, and how to create them. Since then, I’ve incorporated everything into my MSBuild.Sdk.Extras package to make it much easier. Please read the previous post to get an idea of the scenarios.
Using the Extras, most of that is eliminated. Instead, what you need is the following:
- A project for your reference assemblies. This project specifies the
TargetFrameworks
you wish to produce. Note: this project no longer has any special naming or directory conventions. Place it anywhere and call it anything. - A pointer (
ReferenceAssemblyProjectReference
) from your main project to the reference assembly project. - Both projects need to be using the Extras. Add a
global.json
to specify the Extras version (must be1.6.30-preview
or later):And at the top of your project files, change
Sdk="Microsoft.NET.Sdk"
toSdk="MSBuild.Sdk.Extras"
- In your reference assembly project, use a wildcard to include the source files you need, something like:
<Compile Include="..\..\System.Interactive\**\*.cs" Exclude="..\..\System.Interactive\obj\**" />
. -
In your main project, point to your reference assembly by adding an
ItemGroup
with anReferenceAssemblyProjectReference
item like this:<ItemGroup> <ReferenceAssemblyProjectReference Include="..\refs\System.Interactive.Ref\System.Interactive.Ref.csproj" /> </ItemGroup>
In this case, I am using
System.Interactive.Ref
as the project name so I can tell them apart in my editor. - That’s it. Build/pack your main project normally and it’ll restore/build the reference assembly project automatically.
Notes
- The tooling will pass
AssemblyName
,AssemblyVersion
,FileVersion
,InformationalVersion
,GenerateDocumentationFile
,NeutralLanguage
, and strong naming properties into the reference assembly based on the main project, so you don’t need to set them twice. - The
REFERENCE_ASSEMBLY
symbol is defined for reference assemblies, so you can doifdef
‘s on that. - Please see System.Interactive as a working example.
code
more code
~~~~