c#-Revit api-多版本插件.csproj文件

问题描述

我正在尝试为Revit创建一个简单的多版本hello World插件,并且发现了this article,我正尝试着该插件。但是,我走得并不远。我对.csproj文件的工作方式不太熟悉。我之前已经为Revit年份创建了插件,但尚未创建多版本。

这是我下面的.csProj代码。我试图从小处着手,仅处理.net Framework 4.5.2(即Revit 2018)。您还将在底部找到我的项目属性的摘要。 Start External Application: 不再开放,所以我不知道如何通过Revit对其进行调试。

感谢您的帮助和指导。

使用下面的当前.csproj代码,我收到此弹出错误:

enter image description here

.csproj

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFrameworks>net452<!--;net46;net47--></TargetFrameworks>
        <Configurations>Debug;Release</Configurations>
        <!--<Platforms>x64</Platforms>-->
        <OutputPath>bin\Debug\</OutputPath>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Any CPU' ">      
        <DefineConstants>DEBUG</DefineConstants>
        <Optimize>false</Optimize>
        <OutputPath>bin\Debug\</OutputPath>

        <DebugType>full</DebugType>
        <DebugSymbols>true</DebugSymbols>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)'=='Release'">
        <PlatformTarget>x64</PlatformTarget>
        <DebugType>none</DebugType>
        <DebugSymbols>false</DebugSymbols>
    </PropertyGroup>

    <PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
        <DefineConstants>$(DefineConstants);REVIT2018</DefineConstants>
        <!--<AssemblyName>helloWorld</AssemblyName>-->
    </PropertyGroup>
    

    <ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
        <!--<Reference Include="AdWindows">
            <HintPath>......\2018\AdWindows.dll</HintPath>
            <EmbedInteropTypes>false</EmbedInteropTypes>
            <Private>false</Private>
        </Reference>-->
        <Reference Include="RevitAPI">
            <HintPath>C:\Program Files\Autodesk\Revit 2018\RevitAPI.dll</HintPath>          
            <EmbedInteropTypes>false</EmbedInteropTypes>
            <Private>false</Private>
        </Reference>
        <Reference Include="RevitAPIUI">
            <HintPath>C:\Program Files\Autodesk\Revit 2018\RevitAPIUI.dll</HintPath>
            <EmbedInteropTypes>false</EmbedInteropTypes>
            <Private>false</Private>
        </Reference>
    </ItemGroup>

    <ItemGroup>
      <Reference Include="PresentationCore" />
      <Reference Include="System.Windows.Forms" />
    </ItemGroup>
</Project>

项目属性摘要

enter image description here

enter image description here

enter image description here

解决方法

感谢Ehsan分享了他的Github链接。我能够弄清楚。

我将这2行添加到了带有装配名称的属性组中。

<TargetFrameworkProfile />
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>

,然后将它们添加到下面的单独属性组中,这似乎允许我在不同版本中运行它们。到目前为止,我只测试了2018年和2019年,但是看起来很有希望。

<PropertyGroup Condition="$(Configuration.Contains('2018'))">
    <TargetFrameworkVersion>v4.5.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>
,

由于您的帖子,我已经了解了有关多版本插件的知识。现在,对于直接问题,您可以在启动调试过程时通过启动Revit来调试类库。设置如下:

  1. 将您的项目设置为启动项目(在“解决方案探索”面板上右键单击项目=>设置为“启动项目”),使其成为调试时第一个运行的项目

  2. 打开“项目属性”标签,选择“调试”

  3. 从“调试”的“开始操作”中,选择“启动外部程序”。然后单击“浏览”按钮以选择Revit的可执行文件。默认情况下,它应该位于:

    C:\ Program Files \ Autodesk \ your_version_of_revit

  4. 保存过程,构建项目并点击F5(或您设置的用于调试的任何键)

这已经有点晚了,因为您已经解决了问题,但是希望它在某些类似情况下会有所帮助。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...