简体   繁体   English

使用 Visual Studio Code 的 AutoCad .net 项目

[英]AutoCad .net project using Visual Studio Code

I was trying to figure out if it is possible to set and debug a vb.net/C#.net AutoCAD project using VS Code?我想知道是否可以使用 VS Code 设置和调试 vb.net/C#.net AutoCAD 项目? Sorry if this is a silly question but I do not have extensive experience in this area.对不起,如果这是一个愚蠢的问题,但我在这方面没有丰富的经验。 So far I've been able to follow tutorials, set and develop a project using VS Community but couldn't find any guidance on how to do it with VS Code.到目前为止,我已经能够遵循教程,使用 VS 社区设置和开发项目,但找不到有关如何使用 VS Code 进行操作的任何指导。 Thanks in advance提前致谢

Got it working with vscode and Acad2021.让它与 vscode 和 Acad2021 一起工作。 The example works with the following setup:该示例适用于以下设置:

To get debugging working with full .net framework I followed this guide .为了使用完整的 .net 框架进行调试,我遵循了本指南

  1. create a new project with: dotnet new classlib创建一个新项目: dotnet new classlib

  2. change your csproj file to (Note: for different autocad versions different versions of the nuget packages will be needed):将您的 csproj 文件更改为(注意:对于不同的 autocad 版本,需要不同版本的 nuget 包):

     <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <PropertyGroup> <TargetFramework>net48</TargetFramework> <RootNamespace>ProjectName</RootNamespace> <PlatformTarget>x64</PlatformTarget> <DebugType>portable</DebugType> <UseWindowsForms>true</UseWindowsForms> </PropertyGroup> <ItemGroup> <PackageReference Include="AutoCAD.NET" Version="24.0.0"></PackageReference> <PackageReference Include="AutoCADCommands" Version="2020.0.0"></PackageReference> </ItemGroup> </Project>
  3. set your launch.json to:将您的 launch.json 设置为:

     { "version": "0.2.0", "configurations": [ { "name": ".NET Core Attach", "type": "clr", "request": "attach", "processId": "${command:pickProcess}" }, ] }
  4. change the Class1.cs file to:将 Class1.cs 文件更改为:

     using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; namespace AU.KO_WT_TestPlugin { public class Initialization : IExtensionApplication { [Autodesk.AutoCAD.Runtime.CommandMethod("MyFirstCommand")] public void cmdMyFirst() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("\\nI have created my first command."); } void IExtensionApplication.Initialize() { } void IExtensionApplication.Terminate() { } } }
  5. run the command: dotnet build运行命令:dotnet build

  6. open autocad打开 AutoCAD

  7. in autocad run the netload command and load your newly generated dll under PathToProject/bin/debug/net48/ProjectName.dll在 autocad 中运行 netload 命令并在 PathToProject/bin/debug/net48/ProjectName.dll 下加载新生成的 dll

  8. back in vscode press F5 to start debugging回到 vscode 按 F5 开始调试

  9. select the acad.exe process选择 acad.exe 进程

  10. set breakpoint in your c# code在你的 C# 代码中设置断点

  11. in autocad call the command MyFirstCommand在 autocad 中调用命令 MyFirstCommand

  12. debug away调试离开

Notes:笔记:

  • as .net assemblies can't be unloaded in autocad after changing your code and recompiling it with dotnet build, it is necessary to restart autocad and netload the new assembly由于 .net 程序集在更改代码并使用 dotnet build 重新编译后无法在 autocad 中卸载,因此需要重新启动 autocad 并 netload 新程序集
  • It should be possible to create a task that launches autocad and netloads the assembly through a script.应该可以创建一个通过脚本启动 autocad 和网络加载程序集的任务。 I haven't found time to explore that possibility我没有时间去探索这种可能性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM