Skip to content

Third party files

Nice3point edited this page Jun 7, 2023 · 16 revisions

By default, the .dll and .addin files are copied to the output project folder. But often it becomes necessary to add Nuget packages, localization files, configs and other things. To add such files, you need to do three steps in the .csproj project file.

Tagging third-party files

All files that will be copied to the Revit Add-ins folder and also added to the installer must be tagged. Initially, the .addin file is assigned the Tag RootItem, for the main project file AddinItem.

<ItemGroup>
    <RootItem Include="$(ProjectDir)*.addin" />
    <AddinItem Include="$(TargetDir)$(AssemblyName).dll" />
</ItemGroup>

All project files from bin folder:

<ItemGroup>
    <RootItem Include="$(ProjectDir)*.addin" />
    <AddinItem Include="$(TargetDir)*" />
</ItemGroup>

You can add both individual files and groups of files. It makes sense to add different tag names only when the output folder is different. You can find the names of the dll files in the bin folder.

Example

<ItemGroup>
    <RootItem Include="$(ProjectDir)*.addin" />
    <AddinItem Include="$(TargetDir)$(AssemblyName).dll" />
    <!--Files to copy to Revit add-ins folder-->
    <AddinItem Include="$(TargetDir)Azure.Core.dll" />
    <AddinItem Include="$(TargetDir)Azure.Data.Tables.dll" />
    <AddinItem Include="$(TargetDir)Azure.Storage.Common.dll" />
    <AddinItem Include="$(TargetDir)Azure.Storage.Files.Shares.dll" />
    <DataItem Include="Resources\Data\config.txt" />
    <FamilyItem Include="Resources\Families\$(RevitVersion)\Family.rfa" />
    <LocalizationDeItem Include="$(TargetDir)de\$(AssemblyName).resources.dll" />
</ItemGroup>

Remember to use wildcards when adding libraries with similar names. The example above can be optimized to look like:

<ItemGroup>
    <RootItem Include="$(ProjectDir)*.addin" />
    <AddinItem Include="$(TargetDir)$(AssemblyName).dll" />
    <!--Files to copy to Revit add-ins folder-->
    <AddinItem Include="$(TargetDir)Azure.*.dll" />
    <DataItem Include="Resources\Data\*" />
    <FamilyItem Include="Resources\Families\$(RevitVersion)\*" />
    <LocalizationDeItem Include="$(TargetDir)de\*" />
</ItemGroup>

Added all packages that start with Azure, added all files from the Data and Families folders.

Tagging output directories

Initially, the structure of the output folders looks like this:

  • The .addin manifest is located at the root, it is necessary for Revit to detect it.
  • All other files are located in the folder that corresponds to the name of the project.
<PropertyGroup>
    <RootDir>bin\AddIn $(RevitVersion) $(Configuration)\</RootDir>
    <AddinDir>$(RootDir)$(AssemblyName)\</AddinDir>
</PropertyGroup>

RootDir is a buffer folder where all marked files will be copied. Then an installer will be created based on it and the files will be copied to the Revit add-ins folder.

To keep the Revit add-ins folder clean, specify subdirectories based on the AddinDir tag only or his descendants.

Example

<PropertyGroup>
    <RootDir>bin\AddIn $(RevitVersion) $(Configuration)\</RootDir>
    <AddinDir>$(RootDir)$(AssemblyName)\</AddinDir>
    <DataDir>$(AddinDir)\Data</DataDir>
    <FamiliesDir>$(AddinDir)\Families</FamiliesDir>
    <LocalizationDeDir>$(AddinDir)\de</FamiliesDir>
</PropertyGroup>

Copy Task

After we have marked all files and output folders, we need to add a task for Msbuild, copy the first to the second.

Reminder: syntax for calling item @(ItemTag), property $(PropertyTag).

<Copy SourceFiles="@(RootItem)" DestinationFolder="$(RootDir)" />
<Copy SourceFiles="@(AddinItem)" DestinationFolder="$(AddinDir)" />

Establish the relationship between files and folders as you need.

Example

<Copy SourceFiles="@(RootItem)" DestinationFolder="$(RootDir)" />
<Copy SourceFiles="@(AddinItem)" DestinationFolder="$(AddinDir)" />
<Copy SourceFiles="@(DataItem)" DestinationFolder="$(DataDir)" />
<Copy SourceFiles="@(FamilyItem)" DestinationFolder="$(FamiliesDir)" />
<Copy SourceFiles="@(LocalizationDeItem)" DestinationFolder="$(LocalizationDeDir)" />

Result

📂Root
 ┣📜RevitAddIn.addin
 ┗📂RevitAddIn
   ┣📂de
   ┃ ┗📜RevitAddIn.resources.dll
   ┣📂Data
   ┃ ┗📜config.txt
   ┣📂Families
   ┃ ┗📜Family.rfa
   ┣📜Azure.Core.dll
   ┣📜Azure.Data.Tables.dll
   ┣📜Azure.Storage.Common.dll
   ┣📜Azure.Storage.Files.Shares.dll
   ┗📜RevitAddIn.dll
Clone this wiki locally