Manual integration

This method will not be available in a future major release of SmartAssembly. To continue using SmartAssembly with MSBuild, please follow Automatic integration.


This method is only supported for .NET Framework projects built with MSBuild.

You can use SmartAssembly tasks from our NuGet package instead to build any .NET Core, .NET Standard or .NET Framework project. Refer to Automatic integration for more information.

Manually editing your MSBuild project file

To integrate SmartAssembly directly into the build process you will need to manually edit your C# or VB.NET project file:

  1. Create your project in SmartAssembly (see Working with projects) and set the project options (see Working with project settings).
  2. Open your application's .csproj or .vbproj file in an XML editor.

    The .csproj or .vbproj file is actually a MSBuild XML file that you can edit to add SmartAssembly to the build tasks. For more information about the MSBuild XML schema, see the MSBuild documentation on MSDN.
  3. Add references to SmartAssembly at the end of your C# or VB.NET project file, as follows:

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      ...
      
      <!-- SmartAssembly task -->
      <PropertyGroup>
        <SmartAssemblyProjectFile>$(ProjectDir)$(AssemblyName).saproj</SmartAssemblyProjectFile>
        <_SATaskAssembly>SmartAssembly.MSBuild.Tasks, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7f465a1c156d4d57</_SATaskAssembly>
      </PropertyGroup>
    
      <UsingTask TaskName="SmartAssembly.MSBuild.Tasks.Build" AssemblyName="$(_SATaskAssembly)" />
      <Target Name="BuildWithSmartAssembly" AfterTargets="Build" Condition=" '$(Configuration)' == 'Release' ">
        <SmartAssembly.MSBuild.Tasks.Build ProjectFile="$(SmartAssemblyProjectFile)" />
      </Target>
      <!-- /SmartAssembly task -->
    </Project>

    SmartAssembly will only run if you're building your application in Release build configuration. You can adjust this behaviour in Target's Condition property, if needed.

    The <UsingTask> element includes SmartAssembly's major version number. This page has been written for SmartAssembly 7.x. If you are using a different version of SmartAssembly, you will need to change the version number specified in the <UsingTask> element. For example, if you use SmartAssembly 6.12, change the version to Version=6.0.0.0.

  4. The example above uses MSBuild macros to point to your *.saproj file. If your C# project is located in C:\MyApplication\MyProject.csproj, the macro $(ProjectDir)$(AssemblyName).saproj will assume SmartAssembly project is located in C:\MyApplication\MyProject.saproj.

    If needed, you can change the <SmartAssemblyProjectFile> property to point to the absolute or relative path of your .saproj file:
    <SmartAssemblyProjectFile>C:\path\to\project.saproj</SmartAssemblyProjectFile>

  5. If required, add any of the following optional attributes to the SmartAssembly.MSBuild.Tasks.Build element:

    OverwriteAssembly

    Set to True if you want to overwrite the original assembly with the obfuscated one.

    If this option is not set, or set to False, SmartAssembly uses the destination file name from the .saproj project.

    If you set this option to True, SmartAssembly ignores the OverwriteAssembly attribute, if set.

    Input

    If this option is set, SmartAssembly will process the assembly specified as this attribute's value.

    If this option is not set, SmartAssembly will process the assembly specified in the .saproj project.

    This is useful if you want to build an assembly using exactly the same settings as those you chose for a different assembly.

    Output

    If this option is set, SmartAssembly will use this attribute's value as the file name when saving the built assembly.

    If this option is not set, SmartAssembly will use the file name in the .saproj file when saving the built assembly.

    This attribute is ignored if the OverwriteAssembly property is set to True.

    This option is useful if you want to save a test build to a different path from other builds.

  6. Build your assembly with MSBuild. SmartAssembly is run automatically, using the settings in your SmartAssembly project file.


Didn't find what you were looking for?