LoginSignup
0
0

More than 3 years have passed since last update.

Autodesk Inventor API Hacking (C#8.0、そして.NET Core3.0)

Posted at

0. はじめに

2019年9月にリリースされた、C# 8.0、そして.NET Core 3.0に移行するには? という話しです。

1. C# 8.0

1.1 C# 8.0 とは、なんぞや

みんなおなじみ、++C++; // 未確認飛行 Cにある、C# 8.0 の新機能が詳しいです。
私のようなライトなユーザーは、

  • null 許容参照型
  • using 変数宣言
  • null 合体代入 (??=)

は使うかもしれないです。

1.2 有効にするには

今までのProjectで有効にするには、.csprojを編集する必要があります。
が、VisualStudioは賢いので、

using int i;

などとcodeに書くと、IntelliSenseが「C#8.0を有効にする?」と聞いてくるので、それに従えば.csprojを編集してくれます。

1.3 .NET Core 3.0は必須じゃないの?

全機能を使おうとすると、.NET Core 3.0もしくは.NET Standard 2.1が必要です。
しかし、機能は限定されますが、.NET Frameworkでも使えます。
詳しくは、C# 8.0 の新機能 : ターゲットフレームワークをご覧ください。

1.4 Nullableをenableにしたいのですが・・・

Project全体でNullableを有効にするには.csprojに指定する必要があります。
しかし、古い形式の.csprojでは、どうしてもIntelliSenseの警告が消えませんでした。(何か勘違いしているっぽい挙動をする)
そこで、Projectを最新形式に書き換える必要がありました。
参考までに、私のProjectを示します。

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>net472</TargetFramework>
    <RootNamespace>InvAddIn</RootNamespace>
    <LangVersion>8.0</LangVersion>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

  <PropertyGroup>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="Autodesk.Inventor.Interop">
      <HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\assembly\GAC_MSIL\Autodesk.Inventor.Interop\v4.0_23.0.0.0__d84147f8b4276564\Autodesk.Inventor.Interop.dll</HintPath>
    </Reference>
    <Reference Include="stdole">
      <HintPath>..\..\..\..\..\..\Windows\assembly\GAC\stdole\7.0.3300.0__b03f5f7f11d50a3a\stdole.dll</HintPath>
    </Reference>
    <Reference Include="System.Windows.Forms" />
  </ItemGroup>

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="call &quot;%25vsappiddir%25..\..\Common7\Tools\VsDevCmd.bat&quot;&#xD;&#xA;call mt.exe -manifest &quot;$(ProjectDir)$(TargetName).X.manifest&quot; -outputresource:&quot;$(TargetPath)&quot;;#2&#xD;&#xA;XCopy &quot;$(TargetPath)&quot; &quot;%25AppData%25\Autodesk\ApplicationPlugins\$(TargetName)\&quot; /Y /R&#xD;&#xA;XCopy &quot;$(ProjectDir)Autodesk.$(TargetName).Inventor.addin&quot; &quot;%25AppData%25\Autodesk\ApplicationPlugins\$(TargetName)\&quot; /Y /R   &#xD;&#xA;&#xD;&#xA;if exist &quot;$(TargetDir)ja\$(TargetName).resources.dll&quot; (&#xD;&#xA;&#xA;mkdir &quot;%25AppData%25\Autodesk\ApplicationPlugins\$(TargetName)\ja&quot;&#xD;&#xA;XCopy &quot;$(TargetDir)ja&quot; &quot;%25AppData%25\Autodesk\ApplicationPlugins\$(TargetName)\ja\&quot; /S /Y /R&#xD;&#xA;) else (&#xD;&#xA;echo ***jaリソースが存在しません。&#xD;&#xA;)&#xD;&#xA;" />
  </Target>
</Project>

3. .NET Core 3.0

3.1 .Net Core 3.0 とは、なんぞや?

.NETは幾つかの系列に分裂しています。.NET Frameworkも、その1つの流れです。
分裂していると不便だよね、ということで大統一がなされたのが、.NET Core 3.0です。
.NET Frameworkは現状の4.8をもって最後となるようで、以後は.NET Coreが更新される予定です。

3.2 .NET Core 3.0とAddIn開発

現時点(2019/11/26, Inventor 2020)では、.NET Core 3.0用に作られたAddInは、Inventorで動作しません。
Autodeskがサポートするまで、.NET Frameworkを使い続けるほか在りません。

99. 親の記事に戻る

Autodesk Inventor API Hacking (概略)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0