1. Run Visual Studio 2013.
2. Create a new project based on AutoCAD .Net Extension template and set the "MySomeExtensions" name for this.
3. Look, the "MySomeExtensions.csproj.user" file is not exists still. It is necessary to create it and change its content.
3.1. Go to "Debug" tab in the project settings and write anything into the "Command line arguments" field.
3.2. Change a focus. For example, click on the "Working directory" field.
3.3. Now the "MySomeExtensions.csproj.user" file was created as you can see.
3.4. Open the "%ProgramData%\Bushman\config\developing\Autodesk\AutoCAD\debug\readme.txt" file in a text editor and copy to clipboard the XML code, which are located at the end of the file.
3.5. Close the "%ProgramData%\Bushman\config\developing\Autodesk\AutoCAD\debug\readme.txt" file.
3.6. Open the "MySomeExtensions.csproj.user" in a text editor.
3.7. Select all content of the "MySomeExtensions.csproj.user" file and remove it.
3.8. Past the content of the clipboard in the "MySomeExtensions.csproj.user" file. Save it and close.
4. Restart Visual Studio and open the "MySomeExtensions" project again. It is necessary for applying changes what we did for the "MySomeExtensions.csproj.user" file.
5. Go to "Debug" tab in the project settings. You see now its settings are filled. Now the "Start external program" option is selected and has the "C:\Program Files\Autodesk\AutoCAD 2009\acad.exe" value. I.e. as you can guess, now the project is adjusted on compilation and debugging for AutoCAD 2009. Also the "Use remote machine" options is checked and has the "win7x64ac2" as value (we will "speak" about it later).
6. Look ObjectARX SDK reference files location. Also pay attention the Interop assemblies is linked too. The referenced files located in the "ObjectARX 2009\inc-x64" subdirectory.
7. Open the "Application" tab in the project properties. Pay attension on the "Assembly name" and "Target framework" values: "MySomeExtensions.R17.2x64" and .Net Framework 3.5.
8. Open the "Build" tab in the project properties. Look the "Conditional compilation symbols":
AUTOCAD;AUTOCAD_2009;PLATFORM_x64;NET35;AUTOCAD_NEWER_THAN_2008
9. Look the "Target platform" value, it is the "x64".
10. Look at the "Output path" value, it has the
"\\win7x64ac2\public\Debug\extensions\acad-extensions\MySomeExtensions\bin\".
11. Close the project properties window.
12. Open the Commands.cs file.
13. Replace the "// Write your code here..." code row on the "ed.WriteMessage("Hello, World!");" value (row 75).
14. Replace the [Rt.CommandMethod(cmdGroup, "test", "LocalizedNameId",
Rt.CommandFlags.Modal, contextMenuExtensionType, helpFileName,
helpFileTopic)] on the [Rt.CommandMethod("test", Rt.CommandFlags.Modal)] (row 64).
15. Save the changes.
16. Now we need to debug our "super usefull" program. Set the breackpoint in the "tr.Commit();" line (row 74).
17. We will use the remote debugging in this sample. My remote computer is the virtual machine, which is working on the server. We will connect to it through the RDP.
18. When I connected to the remote machine, I run the Remote Debugging Monitor 2013 at first. Now we can do the remote debugging.
19. Clear the output directory. It is locating on the remote machine ("C:\public" directory).
19.1. In the MS Visual Studio run the "Rebuild Solution" command.
20. Press F5 key.
21. On the remote machine was started AutoCAD 2009, as you can see.
22. In the AutoCAD 2009 run the _NETLOAD command and select the "C:\public\Debug\extensions\acad-extensions\MySomeExtensions\bin\MySomeExtensions.R17.2x64.dll" file.
23. In AutoCAD 2009 console you can see the text "The "C:\public\Debug\extensions\acad-extensions\MySomeExtensions\bin\MySomeExtensions.R17.2x64.dll" assembly successfully loaded." now.
24. Run the TEST command in the AutoCAD console. Breackpoint will work now (you can see it in the IDE).
25. Press F5 now and look the AutoCAD console output: "Hello, World!".
26. Ok. Now close AutoCAD 2009.
27. But what if we want to build our project as AnyCPU, instead of x64? Pay attension: Interop assemblies are linked to our project still.
28. WARNING! Remember: don't change the settings of your project (the Application, Build and Debug tabs) through the Visual Studio GUI manually! Their property values are EVALUATED (it evaluate on base target AutoCAD and platform version). If you will change their value in the GUI - it will be static now. Later, in this article, I will discribe how to do it right. Also don't pay attention on the values of current "Solution Platform" in the Visual Studio.
28.1. Open the "MySomeExtensions.csproj" file in the text editor.
29. Set the 2009 value into the CAD_Year_Platform property (instead of old 2009x64 value).
30. Save the changes and close text editor.
31. In the Visual Studio you will see the "File modification detected" window. Press the "Reload all" button.
32. Look references again. You see, the Interop references is not linked now.
33. Also the "Conditional compilation symbols" has the PLATFORM_AnyCPU instead of PLATFORM_x64 now.
34. Also the "Assembly name" is the "MySomeExtensions.R17.2" now instead of "MySomeExtensions.R17.2x64".
34.1. But Object ARX SDK 2009 had not still the managed wrappers in the "inc" subdirectory. Therefore inc-x64 are used still for AutoCAD 2009.
35. Ok, but we want to build this project for the several AutoCAD versions. How to do it?
36. It is wery simple. At first, remove the content of the "C:\public" directory of our remote machine (for purity of experiment).
37. In the Solution Explored do the click of the mouse right button on the "_debug-build-all.bat" file and select the "Open Command Prompt" context menu item. Cmd.exe window will be opened.
38. In the Cmd.exe window write the _d and press the TAB key. The "_debug-build-all.bat" will be written. Press ENTER key. That's all. MSBuild builds your project for all neccessary AutoCAD versions!
39. On the remote machine, in the "C:\public\Debug\extensions\acad-extensions\MySomeExtensions\bin" directory now exist files: MySomeExtensions.dll, MySomeExtensions.R17.2x64.dll, MySomeExtensions.R17.2x86.dll, MySomeExtensions.R19.0.dll, MySomeExtensions.R20.0.dll.
40. You can see, each of DLL file name starts with the "MySomeExtensions" prefix. Sufixes point to the target AutoCAD and platform: R17.2 - is the core version of AutoCAD 2009, R19.0 - AutoCAD 2013, R19.0 - AutoCAD 2015. The x64 and x86 is the target platforms. If the DLL has not the x64 or x86 sufix - its target platform is AnyCPU.
41. But pay attention on the MySomeExtensions.dll file. It hasn't any sufixes. What is it? Into what AutoCAD it can be loaded? The answer is simple: the MySomeExtensions.dll file can be loaded into any AutoCAD, because it is an "entry point". When the MySomeExtensions.dll is loaded into AutoCAD, it finds the most suitable version of your assembly (which name starts with the same name, has the AutoCAD core suffix and (optional) target platform). For example: when the MySomeExtensions.dll will be loaded into the AutoCAD 2009, 2010, 2011 or 2012, then it load the MySomeExtensions.R17.2x64.dll also (because the our platform is x64 and we did't create the MySomeExtensions.R17.2.dll assembly). Other case, when the MySomeExtensions.dll will be loaded into the AutoCAD 2013, 2014, then it load the MySomeExtensions.R19.0.dll also. When the MySomeExtensions.dll will be loaded into the AutoCAD 2015, then it load the MySomeExtensions.R20.0.dll also. Existing of "entry point" does our .net-extension more extensible. For example, when will be released AutoCAD 2016, it is enough to add the 40. You can see, each of DLL file name starts with the "MySomeExtensions" prefix. Sufixes point to the target AutoCAD and platform: R17.2 - is the core version of AutoCAD 2009, R19.0 - AutoCAD 2013, R19.0 - AutoCAD 2015. The x64 and x86 is the target platforms. If the DLL has not the x64 or x86 sufix - its target platform is AnyCPU.
41. But pay attention on the MySomeExtensions.dll file. It hasn't any sufixes. What is it? Into what AutoCAD it can be loaded? The answer is simple: the MySomeExtensions.dll file can be loaded into any AutoCAD, because it is an "entry point". When the MySomeExtensions.dll is loaded into AutoCAD, it finds the most suitable version of your assembly (which name starts with the same name, has the AutoCAD core suffix and (optional) target platform). For example: when the MySomeExtensions.dll will be loaded into the AutoCAD 2009, 2010, 2011 or 2012, then it load the MySomeExtensions.R17.2x64.dll also (because the our platform is x64 and we did't create the MySomeExtensions.R17.2.dll assembly). Other case, when the MySomeExtensions.dll will be loaded into the AutoCAD 2013, 2014, then it load the MySomeExtensions.R19.0.dll also. When the MySomeExtensions.dll will be loaded into the AutoCAD 2015, then it load the MySomeExtensions.R20.0.dll also. Existing of "entry point" does our .net-extension more extensible. For example, when will be released AutoCAD 2016, it is enough to add the MySomeExtensions.R20.1.dll into your extension directory. into your extension directory (if AutoCAD 2016 wil can not load the MySomeExtensions.R20.0.dll).
42. Ok, come back to our project settings... What is the _debug-build-all.bat file? It is a BAT-script which runs the MSBuild with the necessary options for the batch building. The result assemblies are builded with the DEBUG configuration. Similar, the _release-build-all.bat builds all necessary assemblies with the RELEASE configuration.
WARNING! if you will rename your csproj-file later, then you must rename it in the _debug-build-all.bat and _release-build-all.bat files too.
43. But how can I define the target AutoCAD versions for the batch building? It is simple too: Open the "MySomeExtensions.csproj" file and find the "BuildFor" XML element. By default its value is "EntryPoint;2009x86;2009x64;2013;2015". I think you understand what does it mean. :) You can change it as you need and save the changes.
44. What if I want debug for other AutoCAD version, not for AutoCAD 2009? Open the "MySomeExtensions.csproj" file and find the "CAD_Year_Platform" XML element. For example, write the 2010x64, if you want to debug for the AutoCAD 2013x64, or set the 2015, if you want to debug for AutoCAD 2015 AnyCPU. Don't forget to save your changes. When you will do it, all references and project settings will updated immediately (as you saw already earlier).
45. The projects based on this template are portable (between developers). What does it mean? One developer can locate own ObjectARX SDK directories in the "C:\" directory directly. Other - in the "D:\SDK\Autodesk\AutoCAD" (my case), or other location. You can copy your project directory into other computer and it is not necessary to update all its references. How does it work? Ok, look it now.
46. I keep the ObjectARX SDK in the "D:\SDK\Autodesk\AutoCAD" directory. Close Visual Studio and rename this path as "D:\SDK-000\Autodesk\AutoCAD". Open our project in the IDE again. We get the resolved references. Ok, close IDE. Open the "%ProgramData%\Bushman\config\developing\common.props" file and change the value of the "SDKLocation" XML element: the "D:\SDK-000" instead of "D:\SDK". Save the changes. WARNING: The specified way shouldn't end with by the "\" symbol. Open our project again - now all is fine!
47. Ok, but what if you use more than one remote machine for debugging, or use local machine only? This is not a problem! Open the "MySomeExtensions.csproj" file and find the "MachineName" XML element. Write the localhost if you use the local machine. If you want to debug for other remote machine - write its name here. Save your changes. How does it work? Open the "%ProgramData%\Bushman\config\developing\Autodesk\AutoCAD\debug" directory. By default you will see three files: the readme.txt, acad-localhost-debug.props and acad-win7x64ac2-debug.props. This directory contains the debug settings for each machine (local or remote).
For each machine the settings are stored in own file with name acad-MachineName-debug.props, where MachineName is "localhost" or remote machine name.
48. Ok, but what must I do, when the new AutoCAD released by Autodesk? No problem:
48.1. Open the "%ProgramData%\Bushman\config\developing\Autodesk\AutoCAD\acads-list.props" file.
48.2. Add the "When" block at the end for new AutoCAD version by analogy with the previous XML elements. For example, for AutoCAD 2016 you must to add this:Code: [Select]<!-- AutoCAD 2016 -->
<When Condition= "'$(CAD_Year) == 2016'">
<PropertyGroup>
<CADCoreMajor>20</CADCoreMajor>
<CADCoreMinor>1</CADCoreMinor>
<!-- Can be used the .NET 4.5, 4.5.1. -->
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
</When>
48.3. Save the changes and close the file.
48.4. Open the "%ProgramData%\Bushman\config\developing\Autodesk\AutoCAD\acad-common.props" file.
48.5. Find the "<NewerThanPrefix>AUTOCAD_NEWER_THAN_</NewerThanPrefix>" string. Under this line you will see a set of "DefineConstants" XML elements.
48.6. Add the "DefineConstants" block at the end for new AutoCAD version by analogy with the previous XML elements. For example, for AutoCAD 2016 you must to add this:Code: [Select]<DefineConstants Condition= "'$(CAD_Year)' > '2016'">$(DefineConstants);$(NewerThanPrefix)2016</DefineConstants>
48.7. Save the changes and close the file.
48.8. Add the new ObjectARX SDK into your SDK location. That's all.
49. How can I change default settings of template (target AutoCAD version for debugging, target AutoCAD versions for the batch building, etc)? Extract the AutoCAD .NET Extension.zip and edit its content as you need. Archive result back.
50. Common settings are located in the %ProgramData%\Bushman\config\developing directory, and influence on all projects (already existing and what will be created in the future) created on the basis of this template. Each of this settings file is detail commented.
51. Current template version already has necessary settings for AutoCAD 2016.
The Trial and Paid versions set Compilation Constants so I could change the build for different versions using the same code. They are only something I would use to build a plugin for sale that if I wanted a to make a Trial version of and disable some features or change the licensing.I think it is good idea, but bad implementation. You can have the Debug and Release configurations only - it will be enough, because you can set additional compilation constants (for Trial or Paid) through the msbuild parameters. For example, you can write in your cspoj-file something like that:
<DefineConstants>$(Constans);TRACE;DEBUG;</DefineConstants>
MSBuild.exe /t:Rebuild /p:Configuration=Release /p:Constans=TRIAL ".\YourProject.csproj"
MSBuild.exe /t:Rebuild /p:Configuration=Release /p:Constans=PAID ".\YourProject.csproj"
...you can set additional compilation constants (for Trial or Paid) through the msbuild parameters. For example, you can write in your cspoj-file something like that:The MSBUILD method works and yes, it is less complicated in Visual Studio. But I will still do it my way :-P . The advantage of putting those (Trial, Paid etc) configurations in the CSPROJ file means...Code - XML: [Select]
<DefineConstants>$(DefineConstants);TRACE;DEBUG;</DefineConstants>
and to set necessary value for your Constant property, when MSBuild will be building your assembly:Code: [Select]MSBuild.exe /t:Rebuild /p:Configuration=Release /p:Constants=TRIAL ".\YourProject.csproj"
MSBuild.exe /t:Rebuild /p:Configuration=Release /p:Constants=PAID ".\YourProject.csproj"
I think that different methods will work for different people. I also think that we like to use what we are used to using :-)Yes, you are right, of course and your arguments are convincing too. :)
This video (http://www.youtube.com/watch?v=Q1nhPkNUyI0&feature=youtu.be) shows the automatic updating of conditional compilation symbols when target AutoCAD version was changed in the csproj-file. This video is additional for the previous. I have a hope it will be a more clear answer for CADbloke's question about it (he knows what I mean).Yes, it is clear, thank you. My question / observation was I noticed that if I use <Choose>...<When>......</When></Choose> in the CSPROJ file then Visual Studio does not change the settings in the code for the build like it does for <PropertyGroup Condition=.... Note that this is the case for project files that are imported by the main project file, the main project file itself works ok, and it also works ok if you reload the main project.
Yes, it is clear, thank you. My question / observation was I noticed that if I use <Choose>...<When>......</When></Choose> in the CSPROJ file then Visual Studio does not change the settings in the code for the build like it does for <PropertyGroup Condition=.... Note that this is the case for project files that are imported by the main project file, the main project file itself works ok, and it also works ok if you reload the main project.Yes, I saw this problem too, when I was creating my template. In the quote I selected by red\green colors the problem\decission. So I keep in the main csproj-file such individual (for each project) settings as: