Revit二次实现多版本动态引用RevitAPI.dll、RevitAPIUI.dll、AdWindows.dll、UIFramework.dll

1、使用NuGet添加:Revit_All_Main_Versions_API_x64(动态引用)

2、修改工程文件配置:.csproj 

复制如下的配置项

 

 <PropertyGroup Condition="$(Configuration.Contains('2017'))">
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <RevitVersion>2017</RevitVersion>
  </PropertyGroup>
  <PropertyGroup Condition="$(Configuration.Contains('2018'))">
    <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
    <RevitVersion>2018</RevitVersion>
  </PropertyGroup>
  <PropertyGroup Condition="$(Configuration.Contains('2019'))">
    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
    <RevitVersion>2019</RevitVersion>
  </PropertyGroup>
  <PropertyGroup Condition="$(Configuration.Contains('2020'))">
    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
    <RevitVersion>2020</RevitVersion>
  </PropertyGroup>
  <PropertyGroup Condition="$(Configuration.Contains('2021'))">
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <RevitVersion>2021</RevitVersion>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug2017|x64'">
    <OutputPath>bin\Debug2017\</OutputPath>
    <DebugSymbols>true</DebugSymbols>
    <Optimize>false</Optimize>
    <DefineConstants>TRACE;DEBUG;REVIT2017</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug2018|x64'">
    <OutputPath>bin\Debug2018\</OutputPath>
    <DebugSymbols>true</DebugSymbols>
    <Optimize>false</Optimize>
    <DefineConstants>TRACE;DEBUG;REVIT2018</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug2019|x64'">
    <OutputPath>bin\Debug2019\</OutputPath>
    <DebugSymbols>true</DebugSymbols>
    <Optimize>false</Optimize>
    <DefineConstants>TRACE;DEBUG;REVIT2019</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug2020|x64'">
    <OutputPath>bin\Debug2020\</OutputPath>
    <DebugSymbols>true</DebugSymbols>
    <Optimize>false</Optimize>
    <DefineConstants>TRACE;DEBUG;REVIT2020</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug2021|x64'">
    <OutputPath>bin\Debug2021\</OutputPath>
    <DebugSymbols>true</DebugSymbols>
    <Optimize>false</Optimize>
    <DefineConstants>TRACE;DEBUG;REVIT2021</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release2017|x64'">
    <OutputPath>bin\Release2017\</OutputPath>
    <Optimize>true</Optimize>
    <DefineConstants>REVIT2017</DefineConstants>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release2018|x64'">
    <OutputPath>bin\Release2018\</OutputPath>
    <Optimize>true</Optimize>
    <DefineConstants>REVIT2018</DefineConstants>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release2019|x64'">
    <OutputPath>bin\Release2019\</OutputPath>
    <Optimize>true</Optimize>
    <DefineConstants>REVIT2019</DefineConstants>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release2020|x64'">
    <OutputPath>bin\Release2020\</OutputPath>
    <Optimize>true</Optimize>
    <DefineConstants>REVIT2020</DefineConstants>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release2021|x64'">
    <OutputPath>bin\Release2021\</OutputPath>
    <Optimize>true</Optimize>
    <DefineConstants>REVIT2021</DefineConstants>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup>


 <ItemGroup>
    <PackageReference Include="Newtonsoft.Json">
      <Version>12.0.3</Version>
    </PackageReference>
    <PackageReference Include="Revit_All_Main_Versions_API_x64" Version="$(RevitVersion).0.0" />
  </ItemGroup>

重新打开VS,选择一个版本,重新生成

 此时去工程目录下查看就已添加了revit api那些dll

在coding 时,使用对应版本的条件编译符号进行区分每个版本对应不同的api 即可

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值