SmartAssembly 8

Process a project targeting multiple frameworks

If your project targets multiple frameworks with <TargetFrameworks> property, it is recommended to create separate SmartAssembly projects for each target assembly.

Let's say you have a project targeting three different frameworks:

<!-- ProjectA.csproj -->
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netcoreapp3.1;net472;netstandard2.1</TargetFrameworks>
  </PropertyGroup>
</Project>

For the project above you might want to create separate SmartAssembly projects, each pointing to the appropriate input assembly:

  • ProjectA_netcoreapp3.1.saproj - /ProjectA/bin/Release/netcoreapp3.1/ProjectA.dll
  • ProjectA_net472.saproj - /ProjectA/bin/Release/net472/ProjectA.dll
  • ProjectA_netstandard2.1.saproj - /ProjectA/bin/Release/netstandard2.1/ProjectA.dll

Then, you need to add the following code to your .csproj file to point SmartAssembly MSBuild task to correct project for each target framework:

<!-- ProjectA.csproj -->
<Project Sdk="Microsoft.NET.Sdk">
  ...

  <Target Name="SetSmartAssemblyProjectPathForEachTarget" BeforeTargets="BuildWithSmartAssembly">
    <PropertyGroup>
      <SmartAssemblyProjectFile>$(MSBuildProjectDirectory)\$(AssemblyName)_$(TargetFramework).saproj</SmartAssemblyProjectFile>
    </PropertyGroup>
    <Message Importance="High" Text="SmartAssembly project for '$(TargetFramework)' set to: $(SmartAssemblyProjectFile)" />
  </Target>
</Project>

Didn't find what you were looking for?