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
TargetFrameworksyou 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.jsonto specify the Extras version (must be
And at the top of your project files, change
- 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
ReferenceAssemblyProjectReferenceitem like this:
<ItemGroup> <ReferenceAssemblyProjectReference Include="..\refs\System.Interactive.Ref\System.Interactive.Ref.csproj" /> </ItemGroup>
In this case, I am using
System.Interactive.Refas 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.
- The tooling will pass
NeutralLanguage, and strong naming properties into the reference assembly based on the main project, so you don’t need to set them twice.
REFERENCE_ASSEMBLYsymbol is defined for reference assemblies, so you can do
ifdef‘s on that.
- Please see System.Interactive as a working example.