The Visual Studio command line is something that many AVR coders have never used, or used very rarely. It makes at least three .NET components available that may be useful to AVR coders.
ILDasm - The IL Dissasembler,
ILDasm.exe, lets you investigate the contents of a .NET assembly (a DLL or EXE). You can read more about it here.
MSBuild - The MS project build engine,
MSBuild.exe, drives how your projects are compiled. Every time you compile a project in Visual Studio MSBuild is launched in the background to perform that compile. MSBuild is especially handy for web developers because MSBuild can be used to build a project from the command line. You can create great DevOps workflows using MSBuild from the commandline to compile and deploy your web projects without needing to do it interactively from within Visual Studio. This is a topic we'll revisit in another article.
RegAsm - Assembly Registration ,
RegAsm.exe, registers .NET assemblies for use with COM. This enables you to create a great deal of interesting AVR for .NET components that can be used by your AVR Classic applications.
The purpose of this article is to able to make
RegAsm quickly and easily available inside Visual Studio. We're launching a series of articles on how you can create powerful class libaries with AVR for .NET that surface .NET goodies to AVR Classic. For example, the other day a customer needed to create a salted, hashed password for his AVR Classic application. Effective encoding of passwords for storing in databases is crucial these days and .NET offers great facilities to do this—and AVR Classic does not. We helped the customer create a class library with AVR for .NET that quite nicely solves the problem for both AVR for .NET and AVR Classic. Another time we helped a customer add regular expression capabilities to AVR Classic with this technique.
.NET includes many facilities that would be handy for AVR Classic applications including advanced math functions, string operations, HTTP requests, Windows file system access, SQL Server and other database access with ADO.NET, and even using .NET Windows forms from AVR Classic, which would make all of .NET's Windows controls available to AVR Classic. This interoperability should be especially important for AVR Classic shops needing to migrate their apps to AVR for .NET.
We'll address the nuts and bolts of how .NET -> Classic integration comes together in future articles. However, all of those articles require that you have instant, easy access to
RegAsm. It is the key to the .NET to COM interoperabilty. For any shop with AVR Classic and an eye on moving to .NET, bookmark this article!
Visual Studio setup
The solution to making
RegAsm quickly available is to add the Visual Studio command line to Visual Studio as an external tool. The Visual Studio top-level
Tools option provides access to several preconfigured external tools. This article shows how to add the .NET command line (we'll it .NET Dev Prompt in the menu). This will make
RegAsm quickly available—directly in your project's Bin\Debug folder where you need.
To add the .NET command lkine to Visual Studio's external tools:
Start Visual Studio and click
Tools->Externals to bring up the dialog below. Click the
Add button and add the .NET Dev Prompt tool as shown below.
.NET Dev Prompt
/k "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
Set the checkboxes as shown in the image above. Click OK.
Having added a new external tool, you can get to it directly from the Tools menu as shown below:
When you run the .NET Dev Prompt, it starts in the current project's
bin\debug folder. This is handy because that's where the .NET assemblies will most likely be that you'll be registering with
RegAsm. There are several other different arguments available for specifying the initial folder. For use with other commands you might want the DOS command box to open at a different folder. See the full list of VS external tool arguments here.
Argumentsvalue shown above specifies the fully qualified path to the
vsdevcmd.cmdfile for Visual Studio 2015. This file is provided with every version of Visual Studio. If you're using a version of Visual Studio other than 2015, be sure to use the location of your version's
Argumentsvalue. A way to find yours is to open a DOS command box and change the path to
c:\Program Files (x86)and then type
dir vsdevcmd.bat /sand press enter. This will list all occurrences of that file and their parent folders.
One more thing...
With the steps above, you've added easy access to a DOS command box that starts with the necessary path to use
RegAsm (and other .NET tools, like
IlDasm). However, when registering DLLs for COM use,
RegAsm requires command line admin privileges. To ensure the DOS command box starts with admin privileges, whenever you know you're going to need to use
RegAsm from within Visual Studio, start it by right-clicking it on the Windows menu and selecting "Run as administrator" (as shown below). When Visual Studio is run as an administrator, the DOS command box you run from Visual Studio will also be run as an administrator. Any time you need to register a DLL for COM, you'll need to start Visual Studio as an administrator.
If you have Visual Studio pinned to your Windows taskbar, you can right click-its taskbar shortcut and use the context menu shown to use VS as an administrator.
Having done all that, you'll have
RegAsm at the ready anytime you need it. I know you probably don't need it yet, but if you have AVR Classic and AVR for .NET, it will prove very valuable. Watch the new articles list at ASNA.com and watch for the 4Q2018 ASNA newsletter for more content on AVR Classic/AVR for .NET interoperabilty.