Skip to content

Instantly share code, notes, and snippets.

@StudioLE
Created February 22, 2020 12:02
Show Gist options
  • Save StudioLE/05f659d9aee3f43c76f7bdf6a6a40bb0 to your computer and use it in GitHub Desktop.
Save StudioLE/05f659d9aee3f43c76f7bdf6a6a40bb0 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>Debug;Debug One;Release</Configurations>
</PropertyGroup>
<PropertyGroup>
<!-- Please remove the targets you don't need in order
to exclude Revit versions your add-in won't support
use the list below for matching Revit version with .NET target
2014 | net40
2015 | net45
2016 | net451
2017 | net452
2018 | net46
2019 | net47
2020 | net471
For example you can exclude Revit 2014, by simply removing net40 target belows
-->
<TargetFrameworks>net40;net45;net451;net452;net46;net47;net471</TargetFrameworks>
<RuntimeIdentifiers>win</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug One'">
<!-- You could debug just ONE addin version,
instead of building all the versions above.
Just put ONE target from the list above
e.g. if you want to debug ONLY Revit 2019,
put net47 below and switch to 'Debug One' configuration
-->
<TargetFrameworks>net471</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net40' ">
<RevitVersion>2014</RevitVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
<RevitVersion>2015</RevitVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net451' ">
<RevitVersion>2016</RevitVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
<RevitVersion>2017</RevitVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net46' ">
<RevitVersion>2018</RevitVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net47' ">
<RevitVersion>2019</RevitVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net471' ">
<RevitVersion>2020</RevitVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Forcibly set platform to 'x64' and ignore architecture-related problems -->
<PlatformTarget>x64</PlatformTarget>
<Platforms>x64</Platforms>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
<!-- Force the project to use the legacy debugger engine -->
<DebugEngines>{351668CC-8477-4fbf-BFE3-5F1006E4DB1F}</DebugEngines>
<!-- Invert the behavior of new .csproj format - exclude files by default -->
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableDefaultItems>false</EnableDefaultItems>
<!-- Define handy symbols to use in the code in order to accommodate different Revit versions,
e.g. by wrapping legacy / deprecated API calls with #if REVIT2014 | REVIT2015 -->
<DefineConstants>REVIT$(RevitVersion);WINFORMS</DefineConstants>
<PreprocessorDefinitions>$(DefineConstants)</PreprocessorDefinitions>
<!-- Multiple targets can cause obj folder locking by concurrent builds -->
<BuildInParallel>false</BuildInParallel>
<!-- Override 'OutputPath' to Debug/Release + Revit version -->
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\bin\$(Configuration)\$(RevitVersion)</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="$(Configuration.Contains('Debug'))">
<DefineConstants>$(DefineConstants);DEBUG</DefineConstants>
<DebugType>full</DebugType>
<OutputPath>..\bin\Debug\$(RevitVersion)</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup Condition="$(DefineConstants.Contains('WINFORMS'))">
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autodesk.Revit.SDK" Version="2014.*" Condition=" '$(RevitVersion)' == '2014' " PrivateAssets="All" />
<PackageReference Include="Autodesk.Revit.SDK" Version="2015.*" Condition=" '$(RevitVersion)' == '2015' " PrivateAssets="All" />
<PackageReference Include="Autodesk.Revit.SDK" Version="2016.*" Condition=" '$(RevitVersion)' == '2016' " PrivateAssets="All" />
<PackageReference Include="Autodesk.Revit.SDK" Version="2017.*" Condition=" '$(RevitVersion)' == '2017' " PrivateAssets="All" />
<PackageReference Include="Autodesk.Revit.SDK" Version="2018.*" Condition=" '$(RevitVersion)' == '2018' " PrivateAssets="All" />
<PackageReference Include="Autodesk.Revit.SDK" Version="2019.*" Condition=" '$(RevitVersion)' == '2019' " PrivateAssets="All" />
<PackageReference Include="Autodesk.Revit.SDK" Version="2020.*" Condition=" '$(RevitVersion)' == '2020' " PrivateAssets="All" />
</ItemGroup>
<Target Name="PreventRevitSDKCopyLocal" AfterTargets="ResolveReferences">
<ItemGroup>
<!-- A temporary fix for Revit SDK files being copied to the output folder -->
<ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'Autodesk.Revit.SDK'" />
</ItemGroup>
</Target>
<ItemGroup>
<!-- Add-in manifest is processed via MSBuild -->
<Content Include="AddinManifest.addin">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
<!-- Don't use standard resource generator, since it doesn't allow
one to use strings containing spaces -->
<EmbeddedResource Include="Properties\Resources.resx">
<Generator />
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.ru-RU.resx">
<Generator />
</EmbeddedResource>
<EmbeddedResource Include="Resources\**\*.*">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</EmbeddedResource>
<Content Include="Properties\launchSettings.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="RibbonHelper.cs" />
<Compile Include="App.cs" />
<Compile Include="ExternalCommand.cs" />
<Compile Include="RibbonCommand.cs" />
<Compile Include="StringLocalizer.cs" />
<Compile Include="ZeroDocStateAvailability.cs" />
</ItemGroup>
<PropertyGroup>
<RootNamespace>RevitAddin1</RootNamespace>
<AssemblyName>RevitAddin1</AssemblyName>
<Authors>Your name</Authors>
<PackageId>sample.vendor.id.change.it</PackageId>
<Company>Acme Ltd</Company>
<PackageProjectUrl>http://example.com/test</PackageProjectUrl>
<Product>The description for your application goes here</Product>
<Version>0.1.2</Version>
<NeutralLanguage>en</NeutralLanguage>
</PropertyGroup>
<Target Name="CreateAddinManifest" AfterTargets="AfterBuild">
<ItemGroup>
<AddinManifest Include="$(OutputPath)\$(AssemblyName).addin" />
</ItemGroup>
<ReplaceFileText InputFilename="AddinManifest.addin" OutputFilename="@(AddinManifest)" MatchExpression="VendorDescription&gt;(.*?)&lt;" ReplacementText="VendorDescription&gt;$(Authors), $(Company), $(PackageProjectUrl)&lt;" />
<ReplaceFileText InputFilename="@(AddinManifest)" OutputFilename="@(AddinManifest)" MatchExpression="FullClassName&gt;((.*?)\.)+" ReplacementText="FullClassName&gt;$(RootNamespace)." />
<ReplaceFileText InputFilename="@(AddinManifest)" OutputFilename="@(AddinManifest)" MatchExpression="&lt;Name&gt;(.*?)&lt;" ReplacementText="&lt;Name&gt;$(Product)&lt;" />
<ReplaceFileText InputFilename="@(AddinManifest)" OutputFilename="@(AddinManifest)" MatchExpression="&lt;VendorId&gt;(.*?)&lt;" ReplacementText="&lt;VendorId&gt;$(PackageId)&lt;" />
<ReplaceFileText Condition="'$(Configuration)' == 'Release'" InputFilename="@(AddinManifest)" OutputFilename="@(AddinManifest)" MatchExpression="Assembly&gt;(.*?)&lt;" ReplacementText="Assembly&gt;$(AssemblyName).dll&lt;" />
<ReplaceFileText Condition="$(Configuration.Contains('Debug'))" InputFilename="@(AddinManifest)" OutputFilename="@(AddinManifest)" MatchExpression="Assembly&gt;(.*?)&lt;" ReplacementText="Assembly&gt;$([System.IO.Path]::GetFullPath('$(OutputPath)'))$(AssemblyName).dll&lt;" />
</Target>
<UsingTask Condition="'$(MSBuildRuntimeType)' == 'Full'" TaskName="ReplaceFileText" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<InputFilename ParameterType="System.String" Required="true" />
<OutputFilename ParameterType="System.String" Required="true" />
<MatchExpression ParameterType="System.String" Required="true" />
<ReplacementText ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs"><![CDATA[
File.WriteAllText(OutputFilename,Regex.Replace(File.ReadAllText(InputFilename),MatchExpression,ReplacementText));
]]></Code>
</Task>
</UsingTask>
<UsingTask Condition="'$(MSBuildRuntimeType)' == 'Core'" TaskName="ReplaceFileText" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<InputFilename ParameterType="System.String" Required="true" />
<OutputFilename ParameterType="System.String" Required="true" />
<MatchExpression ParameterType="System.String" Required="true" />
<ReplacementText ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs"><![CDATA[
File.WriteAllText(OutputFilename,Regex.Replace(File.ReadAllText(InputFilename),MatchExpression,ReplacementText));
]]></Code>
</Task>
</UsingTask>
<Target Name="CopyAddinsToAppData" AfterTargets="CreateAddinManifest" Condition="$(Configuration.Contains('Debug'))">
<!-- Copy newly compiled add-in files to AppData folder (before starting the debugger) -->
<Message Importance="high" Text="Copying addin file into Revit Addin folder" />
<ItemGroup>
<AddinFiles Include="$(OutputPath)\..\**\*.addin" />
</ItemGroup>
<Copy SourceFiles="@(AddinFiles)" DestinationFolder="$(AppData)\Autodesk\Revit\Addins\%(RecursiveDir)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Retries="3" RetryDelayMilliseconds="300" />
</Target>
<Target Name="CleanAddinsInAppData" AfterTargets="AfterClean">
<!-- Delete previously deployed to AppData folder add-in files -->
<ItemGroup>
<AddinFiles Include="$(AppData)\Autodesk\Revit\Addins\**\$(AssemblyName).*" />
</ItemGroup>
<Delete Files="@(AddinFiles)" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment