How to detect if an API is deprecated?

The APIs in solidworks DLLs don’t have deprecated attributes, so it’s hard to find out which APIs we should stop using. But my oldest product code is now many years old so there should be some improvements available.

I’m looking for a way to:

  • Add solidworks 2023 DLLs to my project. I’m using SolidDNA and that framework always uses the latest version.
  • Add a property with the oldest SW version I support, currently SW2018.
  • Get warnings or hints when new API versions are available.

How could we achieve this? Scrape the API docs and write an analyzer for Visual Studio? I’m new to both, so that’s not a trivial task.

The best I can think of is to use a try->catch block to see if the newest API call works. If not, try the call again with the older API call.

If you’re using/updating SolidDNA, you could potentially tie an attribute to the wrapped calls that looks at the SW version and determines which call should be used based on SW version.

It’s not a small amount of work.

I’m hoping for something that shows warnings at design time. I’d love to take the guesswork and manual searching out of writing modern code. I prefer not to go through 100k lines to find old API calls in my product.

Hmmm

I think you can develop a VS extension that will do the guesswork for you.

1 Like

Hey Peter

I have an unfinished project from last year, that scraped the help files.

I was wanting to automatically write extension methods with annotations and picking up the deprecated methods was included.

I can’t quite remember how I left it… I recall I did actually get my libraries to compile after a few manual edits caused by errors in the docs… but I rewrote the project as I was having too much fun and then ran out of time lol

But it was pretty easy to read the helpfiles. Did I unzip them? That was a tip from Artem… And then I used AngleSharp and the AngleSharpXPath nuget too.

I created a bunch of json files from the helpfiles and then used these to write my extensions methods… Yeah it wrote extension wrappers for the entire api lol

It should be quite easy to create a list of obsolete methods… but then I’m not too sure what you’d do with them.

1 Like

Oh, you ‘scraped’ the local help files? Clever :slight_smile:

I think we could create an analyzer or a VS extension. I have zero experience with both, so that sounds like a fun weekend project.

1 Like

Artem gave me that tip

weekend? lol

Start a public repo with an MIT license, I will contribute with a few commits to the VS extension.

This is a totally fun project. The idea to is to add a squiggly line under the deprecated with a tooltip saying you should be using this method instead and a link to the Solidworks online help.

That would be awesome! Will do that soon.

1 Like

There is a VS extension for api link in github, but no version check feature now.

Cool stuff. I’ll try that sometime.

I found that xcad had some code about hwo to use different version api, maybe helpful.

Xcad is a framework so it should be compatible with many Solidworks versions. So they are checking the version at runtime. I want to go through all my code and find which apis are deprecated, so that’s a different task.

Thanks! it’s a different task. Maybe an analyzer can solve this as you said.