You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Visual Studio 2019中创建SwCSharpAddin项目?创建时遇报错怎么办?

Hey there! Let’s tackle your questions about building a SwCSharpAddin project in Visual Studio 2019, plus fix those frustrating errors that pop up along the way.

1. Step-by-Step Guide to Create a SwCSharpAddin Project in Visual Studio 2019

Let’s walk through this step by step to make sure you don’t miss anything:

  • First, double-check you have Visual Studio 2019 installed with the .NET Desktop Development workload. If not, fire up the Visual Studio Installer, hit "Modify", and check that workload to install the necessary C# tools and frameworks.
  • Launch Visual Studio 2019, then click Create a new project from the start screen.
  • In the project search bar, type SwCSharpAddin. If you don’t see this template, you need the SolidWorks API Templates extension:
    • Go to Extensions > Manage Extensions in Visual Studio.
    • Search the Online marketplace for "SolidWorks API Templates", download and install it, then restart Visual Studio to load the extension.
  • Once you spot the SwCSharpAddin template, select it and click Next.
  • Name your project, pick a save location, and click Create to generate the project structure.
  • You’ll see the default add-in setup: a class implementing ISwAddin, the required Connect/Disconnect methods, and attributes like SwAddinAttribute to register the add-in with SolidWorks.
  • Before building, tweak a few project settings:
    • Right-click the project > Properties > Build. Under "Conditional compilation symbols", add the symbol matching your SolidWorks version (e.g., SW2019 for SolidWorks 2019 – check the SolidWorks API docs for your exact version’s symbol).
    • Head to References and confirm the SolidWorks interop assemblies (SolidWorks.Interop.sldworks, SolidWorks.Interop.swconst, SolidWorks.Interop.swpublished) are present. The template should add these automatically, but it never hurts to double-check.
  • Build the project, and you’ll get a .dll file ready to load into SolidWorks.
2. Common Errors & Fixes When Creating SwCSharpAddin Projects

Here are the most frequent issues users run into, plus how to fix them:

Error: "The template 'SwCSharpAddin' could not be found"

Exact Error Message: We couldn't find a template matching your search criteria.

  • How to Fix:
    • Install the SolidWorks API Templates extension via Visual Studio’s Manage Extensions (as outlined in the creation steps above).
    • If you already installed it, restart Visual Studio – extensions often don’t activate until you reboot the IDE.
    • Make sure your Visual Studio 2019 is updated to the latest version (go to Help > Check for Updates) – older builds might not support the template pack.

Error: "The type or namespace name 'SolidWorks' could not be found"

Exact Error Message: The type or namespace name 'SolidWorks' could not be found (are you missing a using directive or an assembly reference?)

  • How to Fix:
    • Right-click your project > Add > Reference > Browse. Navigate to your SolidWorks installation folder (typically C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS).
    • Select SolidWorks.Interop.sldworks.dll, SolidWorks.Interop.swconst.dll, and SolidWorks.Interop.swpublished.dll, then click OK.
    • Alternatively, if you have the SolidWorks API SDK installed, these references will show up under Assemblies > Extensions in the Reference Manager.

Error: "Undefined conditional compilation symbol 'SWXXX'"

Exact Error Message: The name 'swDocumentTypes_e' does not exist in the current context (or similar API type/constant errors)

  • How to Fix:
    • Go to project properties > Build > "Conditional compilation symbols". Add the correct symbol for your SolidWorks version (e.g., SW2020 for SolidWorks 2020). You can find the exact symbol for your version in the SolidWorks API documentation.
    • Also, make sure you have the using SolidWorks.Interop.swconst; directive at the top of your code file to access the API constants.

内容的提问来源于stack exchange,提问作者风何之

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 08:02:29