SmartAssembly 8

Help for older versions available.

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:

  1. <!-- ProjectA.csproj -->
  2. <Project Sdk="Microsoft.NET.Sdk">
  3. <PropertyGroup>
  4. <TargetFrameworks>netcoreapp3.1;net472;netstandard2.1</TargetFrameworks>
  5. </PropertyGroup>
  6. </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:

  1. <!-- ProjectA.csproj -->
  2. <Project Sdk="Microsoft.NET.Sdk">
  3. ...
  4.  
  5. <Target Name="SetSmartAssemblyProjectPathForEachTarget" BeforeTargets="BuildWithSmartAssembly">
  6. <PropertyGroup>
  7. <SmartAssemblyProjectFile>$(MSBuildProjectDirectory)\$(AssemblyName)_$(TargetFramework).saproj</SmartAssemblyProjectFile>
  8. </PropertyGroup>
  9. <Message Importance="High" Text="SmartAssembly project for '$(TargetFramework)' set to: $(SmartAssemblyProjectFile)" />
  10. </Target>
  11. </Project>

Didn't find what you were looking for?