Author Topic: Smart templates for AutoCAD .NET Extensions and their Unit Tests  (Read 4302 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
I published it here. Documentation, videos, code samples also presented.

ChrisCarlson

  • Guest
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #1 on: April 17, 2015, 03:56:07 PM »
Very nice, 2013 VS and 2016 AutoCAD?

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #2 on: April 17, 2015, 11:26:08 PM »
Very nice, 2013 VS and 2016 AutoCAD?
Any AutoCAD newer than 2008. It is possible to change target VS also (I use VS 2013 and AutoCAD 2009).

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #3 on: April 17, 2015, 11:50:11 PM »
I can add capability switching the target VS versions through settings of config-files also. Current version assumes the using of VS 2013 by default. But VS 2010 can't work with .Net Framework newer than 4.0. If you have installed VS 2013 also, then you can use these templates in any VS newer than 2008. At this case for building will use msbuild by VS 2013 (even if you launch building from VS 2010 - the compilation will successful even for AutoCAD 2016).
« Last Edit: April 17, 2015, 11:54:35 PM by Andrey Bushman »

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #4 on: April 24, 2015, 07:57:30 AM »
Hi Andrey and all following this and this and this, I hate to be the one to throw a spanner in the works but I have had a lot of issues with One-Size-Makes-All projects that import project settings when the main project uses Nuget packages, or if it imports a project as a reference. When the .NET framework changes for your main project breaks the Nuget package because the <HintPath> to the Nuget packages depend on the .NET framework when the package is added and so do their dependent packages in a lot of cases. The Microsoft BCL portable class library (which many Nuget packages seem to use) adds more recent .NET functionality to .NET 4, is a big problem in this situation - that is an issue with CADtest at the moment, it builds with warnings about conflict in referenced assemblies because it was originally a .NET 4.0 project and is lately a .NET 4.5 project.

I'm still thinking this one through, perhaps a way is to set up some Nuget host projects that use different versions of .NET and set those projects as conditional references to the main project(s) depending on the version of NET they use. I am just thinking out loud with that - I really don't think it will work.

Perhaps separate projects for each separate build is the most simple and maintainable answer. You can still re-use the same code by editing the CSPROJ file with something like ...
Code - XML: [Select]
  1. <Compile Include="CoreConsoleAppInitializeTerminate.cs" />
  2. <Compile Include="CoreConsoleCommands.cs" />
  3. <Compile Include="..\CADblokeFindReplace\Replacer\*.*">
  4.   <Link>Replacer\%(RecursiveDir)%(Filename)%(Extension)</Link>
  5. </Compile>
  6. <Compile Include="..\CADblokeFindReplace\Searcher\*.*">
  7.   <Link>Searcher\%(RecursiveDir)%(Filename)%(Extension)</Link>
  8. </Compile>
  9.  

I think including all your code and then excluding things that break a specific build it is probably the most maintainable way to go, you can't just keep manually adding a class to each project as you go...
Code - XML: [Select]
  1. <Compile Include="...\Src\**\*.cs" Exclude="AssemblyInfo.cs;**\Temp*.cs" />  <!-- *.* or *.cs ... you decide -->
  2. <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
  3.  
Code that is specific to a Build Version just goes directly into that project, everything else is added to the master Source project. The upside of this is you can see all of the syntax, intellisense and mistakes (oh, is that just me?) in Visual Studio. You can unload them if you are sick of looking at them.

Ultimately my goal, and for Andrey too, I believe, is to build plugins for many different applications with the same source code, and to reliably test that code against those different applications.

It must be
  • easy to use and
  • easy to maintain.

Currently my solution is neither.

Darn.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #5 on: April 24, 2015, 08:17:02 AM »
Hi Ewen,

I created second version of  these templates. There are many improvements. From readme.txt:

Quote
This is ANT v2.0.

********************************************************************************
BUG FIXES:

- In the "Installing and first configuring" chapter of ant.chm file was
corrected a misprint (was written the "NUnit" word instead of "Gallio").

- In the top comment of the code sources the $safeitemname$ was replaced with
a $itemname$. Now it correctly shows the code source file name.

- Corrected the incorrect logic in the
"%ProgramData%\Bushman\config\developing\Autodesk\AutoCAD\acad-civil-common.props"
file. Now AutoCAD references are correctly linked for AutoCAD 2011-2013 AnyCPU
also.

********************************************************************************
CHANGES:

- Updated the "Unit Tests code samples" chapter in the ant.chm file.

- Code sources moved from the "scr" subdirectory to project directory. The
"scr" subdirectory removed.

- Was deleted a possibility of switching of using aliases in the code of templates.

- From the Unit Testing project templates removed the files:

  Work.cs
  Work.resx
  TestTemplates.cs

- Removed the "CustomParameters" block from the *.vstemplate of templates. Now
there is no need in editing these [*.vstemplate] files.

- Now by default the name of namespaces is the same like the safe name of project.

- All code sources updated (many improvings are made).

- Updated the logic of BAT-file generation.

- Documentation updated according the changes.

********************************************************************************
WHAT'S NEW:

- Added the item templates:
 
  AutoCAD Extension Entry Point 
  AutoCAD commands
  AutoCAD empty class 
  AutoCAD ExtensionApplication class
  AutoCAD Unit Tests class 
  AutoCAD Civil 3D commands
  AutoCAD Civil 3D empty class
  AutoCAD Civil 3D ExtensionApplication class
  AutoCAD Civil 3D Unit Tests class

- Now the summary HTML-report of NUnit tests will be created additionaly by the
"run-tests-in-all-autocads.bat" script. It has the links to detailed reports.

- Added console utility for generation of all necessary *.props files for your
local and remote machines. Now you point SDK location only - it is enough. Also
this program edit templates as you need.

********************************************************************************

It is not published, because I am testing it still. I don't use Nuget packages in my projects of AutoCAD .net extentions and their unit tests. Therefore I haven't any problem with Nuget. I will add the info about the problems with NUnit for these templates in the documentation.

« Last Edit: April 24, 2015, 08:25:07 AM by Andrey Bushman »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #6 on: April 24, 2015, 08:34:51 AM »
Quote
or if it imports a project as a reference.
Hm... My unit tests have a reference to the target project of testing (autocad .net extension). Both compiled and work without any problems. Can you send me "hello world" with such problem?

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #7 on: April 24, 2015, 08:40:21 AM »
I will add the info about the problems with NUnit for these templates in the documentation.
Also I added the warning here.

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #8 on: April 24, 2015, 08:50:44 AM »
Hi Andrey,

I will try to get to your latest updates and test them.

A good example of what happens to Nuget packages when the .NET framework changes is CADtest. The VB project from there won't even build for me (I think the project owner must be a bit silly :uglystupid2:) but the C# project builds with lots of warnings. This is because it was originally a .NET 4.0 project and I haven't fixed that part of it. The Nuget package for NUnit lite 3 has different dependencies between the different .NET frameworks ... https://www.nuget.org/packages/NUnitLite/3.0.0-beta-1

I am still thinking about this.

It is interesting that Visual Studio 2015 has Shared Projects from Xamarin, these are projects that just have source code and are not compiled. You add the Shared Project to your projects that build the same way you add a project reference.

You can also do this in Visual Studio 2013 using an extension. I have installed it but haven't tried it yet. I see from the Q & A that some people are having problems but it has had more than 10,000 downloads so it may not be big problems.

Shared projects look more like something for portable classes than for whole applications so that may just be a new level of complexification (translation: "hell").

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #9 on: April 24, 2015, 08:57:10 AM »
It is interesting that Visual Studio 2015 has Shared Projects
I see this:
Quote
The page you are looking is not found. We are looking into it. Will get back to you soon.

CADbloke

  • Bull Frog
  • Posts: 342
  • Crash Test Dummy
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #10 on: April 24, 2015, 09:20:54 AM »
I see this:
Quote
The page you are looking is not found. We are looking into it. Will get back to you soon.

Odd, works for me. Perhaps is was broken in Translation ?

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #11 on: April 24, 2015, 09:23:10 AM »
Odd, works for me. Perhaps is was broken in Translation ?
I don't know.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #12 on: May 12, 2015, 12:05:55 PM »
ANT version 1.1 is released.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Smart templates for AutoCAD .NET Extensions and their Unit Tests
« Reply #13 on: May 13, 2015, 03:11:42 AM »
I added Why did it appear? on the main page.
« Last Edit: May 13, 2015, 03:41:02 AM by Andrey Bushman »