Skip to content

Instantly share code, notes, and snippets.

@ricaun
Last active May 8, 2025 17:31
Show Gist options
  • Save ricaun/b5b1d212238e277c5df46221f6d0834b to your computer and use it in GitHub Desktop.
Save ricaun/b5b1d212238e277c5df46221f6d0834b to your computer and use it in GitHub Desktop.
Copy BundleFiles Target for Autodesk AutoCAD
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<CopyBundleFiles>true</CopyBundleFiles>
</PropertyGroup>
<PropertyGroup>
<BundleDestinationFolder>$(AppData)\Autodesk\ApplicationPlugins\$(MSBuildProjectName).bundle</BundleDestinationFolder>
</PropertyGroup>
<Target Name="_CopyBundleFiles" AfterTargets="Build" Condition="$(CopyBundleFiles) and $(TargetFramework) != ''">
<ItemGroup>
<PackageContentsFile Include="$(ProjectDir)\PackageContents.xml" />
<BundleItems Include="$(OutputPath)**\*" />
</ItemGroup>
<Copy SourceFiles="@(BundleItems)" SkipUnchangedFiles="false" DestinationFolder="$(BundleDestinationFolder)\%(RecursiveDir)" ContinueOnError="true" Retries="1" />
<Copy SourceFiles="@(PackageContentsFile)" SkipUnchangedFiles="false" DestinationFolder="$(BundleDestinationFolder)" ContinueOnError="true" />
<Message Text="$(MSBuildProjectName) -&gt; $(BundleDestinationFolder) -&gt; [@(BundleItems -> '%(Filename)%(Extension)', ', ')] ($(TargetFramework)) " Importance="high" />
</Target>
<Target Name="_CleanBundleFiles" AfterTargets="Clean" Condition="$(CopyBundleFiles) and $(TargetFramework) != ''">
<RemoveDir Directories="$(BundleDestinationFolder)" ContinueOnError="true" />
<Delete Files="$(BundleDestinationFolder)\PackageContents.xml" ContinueOnError="true" />
</Target>
</Project>
@ricaun
Copy link
Author

ricaun commented May 7, 2025

PackageContents.xml

<?xml version="1.0" encoding="utf-8"?>
<ApplicationPackage SchemaVersion="1.0" AutodeskProduct="AutoCAD" Name="AutoCADAddin.Sample" AppVersion="1.0.0" ProductType="Application" ProductCode="11111111-2222-3333-4444-555555555555">
  <CompanyDetails Name="ricaun" />
  <Components Description="AutoCAD 2019-2024">
    <RuntimeRequirements OS="Win64" Platform="AutoCAD*" SeriesMin="R23.0" SeriesMax="R24.3"/>
    <ComponentEntry AppName="AutoCADAddin.Sample" ModuleName="./AutoCADAddin.Sample.dll" LoadOnAppearance="True" />
  </Components>
  <Components Description="AutoCAD 2025+">
    <RuntimeRequirements OS="Win64" Platform="AutoCAD*" SeriesMin="R25.0" />
    <ComponentEntry AppName="AutoCADAddin.Sample" ModuleName="./AutoCADAddin.Sample.dll" LoadOnAppearance="True" />
  </Components>
</ApplicationPackage>

LoadOnAppearance is used to force to load when AutoCAD is already open.

@ricaun
Copy link
Author

ricaun commented May 7, 2025

AutoCADVersion to AutoCADInternalVersion

  <PropertyGroup>
    <AutoCADInternalVersion Condition="$(AutoCADVersion) == 2019">23.0</AutoCADInternalVersion>
    <AutoCADInternalVersion Condition="$(AutoCADVersion) == 2020">23.1</AutoCADInternalVersion>
    <AutoCADInternalVersion Condition="$(AutoCADVersion) == 2021">24.0</AutoCADInternalVersion>
    <AutoCADInternalVersion Condition="$(AutoCADVersion) == 2022">24.1</AutoCADInternalVersion>
    <AutoCADInternalVersion Condition="$(AutoCADVersion) == 2023">24.2</AutoCADInternalVersion>
    <AutoCADInternalVersion Condition="$(AutoCADVersion) == 2024">24.3</AutoCADInternalVersion>
    <AutoCADInternalVersion Condition="$(AutoCADVersion) == 2025">25.0</AutoCADInternalVersion>
    <AutoCADInternalVersion Condition="$(AutoCADVersion) == 2026">25.1</AutoCADInternalVersion>
  </PropertyGroup>
  
  <ItemGroup>
    <PackageReference Include="AutoCAD.NET" Version="$(AutoCADInternalVersion).*" IncludeAssets="build; compile" PrivateAssets="All" />
  </ItemGroup>

@ricaun
Copy link
Author

ricaun commented May 7, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment