ClickOnce with Visual C++ 2010 Runtime Libraries (x86) Prerequisite

This article applies to Visual Studio 2010 SP1.

ClickOnce provides a nice utility to include prerequisites in the deployment. But the VC++ Runtime x86 shipped with VS is bugged. As a result, the ClickOnce installer will try to download and install the VC++ Runtime all the time. And most of the times, this installation will fail because it finds that a newer version has already been installed.

There are in fact two things going wrong here:

1) The installer tries to detect the installed VC++ Runtime with a wrong product code. So when it cannot find the wrong code, it thinks the VC++ Runtime is not installed and tries to download one.

2) It uses a wrong download link to download the older version of the runtime, which would fail if you already has a newer one.

Fixes:

1) Go to C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\vcredist_x86\product.xml. Find this section:

<InstallChecks>
 <MsiProductCheck Property="VCRedistInstalled" Product="{6EE91C1A-A2E7-38CD-AEBB-3B900A4D8868}"/>
</InstallChecks>

The product code needs to be changed to {F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}.

2) Go to C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\vcredist_x86\en\package.xml. Find this section:

<String Name="VCRedistExe">http://go.microsoft.com/fwlink/?LinkID=177916&amp;clcid=0x409</String>

The LinkID needs to be changed to 210621.

 

references:

http://stackoverflow.com/questions/7785328/visual-c-2010-runtime-libraries-prerequisite-keeps-popping-up-on-a-vs-2010-cre

https://connect.microsoft.com/VisualStudio/feedback/details/726264/msdn-forum-vcredist-x86-bootstrapper-package-xml-content-wrong

“-529697949 (0xe06d7363) Microsoft C++ Exception” with Revit 2015+ API

ERROR: “The program Revit.exe has exited with code -529697949 (0xe06d7363) Microsoft C++ Exception.”

I guess while developing with Revit 2015+ API, you hit this error when you are trying to start Revit in VS to debug? You may want to go to VS – Tools – Options – Debugging, simply check “Use Managed Compatibility Mode”. And try again. Good luck!

4-21-2014 3-28-30 PM

4-21-2014 4-58-58 PM

EXTERNAL COMMAND IN 10 STEPS FOR REVIT 2015/2016 API

This is not yet another getting started tutorial on Revit API, but rather a concise checklist and minimum development environment that one can test and verify the system is working before diving into more complex code.

0. the prerequisites:

Make sure Revit 2015/2016 and Visual Studio 2012/2013 is installed. Revit 2015 will not work with older Visual Studios.

1. the project:

Create a new “Class Library” project in “Visual C#” with “.NET Framework 4.5”.

2. the references:

Add RevitAPI.dll, RevitAPIUI.dll and System.Windows.Forms as project references.

Change the “Copy Local” property of RevitAPI.dll and RevitAPIUI.dll to false.

3. the class:

Inherit the Autodesk.Revit.UI.IExternalCommand interface.

Add the following class attribute code before the class declaration.

[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Automatic)]

4. the method:

Implement the Execute method of the inherited interface.

public Autodesk.Revit.UI.Result Execute(
    Autodesk.Revit.UI.ExternalCommandData commandData,
    ref string message,
    Autodesk.Revit.DB.ElementSet elements)
{
    System.Windows.Forms.MessageBox.Show("Hello World");
    return Autodesk.Revit.UI.Result.Succeeded;
} 

5. the assembly:

Press F6 and VS should report “Build succeeded”.

Note the output path of the dll file shown in the Output window.

6. the GUID:

Create a unique ID for your command.

7. the .addin file

Create an empty text file in: C:\Users\yourUserName\AppData\Roaming\Autodesk\Revit\Addins\201X

(or C:\ProgramData\Autodesk\Revit\Addins\201X).

Change the file name to anyNameWillWork.addin.

Open the file and copy or type the following code:

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
    <AddIn Type="Command">
        <Assembly>C:\yourAddinPath\youAddinName.dll</Assembly>
        <AddInId>yourLong-Long-Long-Long-GuidGoesHere</AddInId>
        <FullClassName>yourAddinNamespace.YourAddinClassName</FullClassName>
        <Text>ExternalCommandTest</Text>
        <VendorId>LZNT</VendorId>
    </AddIn>
</RevitAddIns>

8. DONE!

Now start Revit and you should see an “Add-Ins” tab at the end of Revit tabs, in which there is an “External Tools” button with the newly created External Command.

9. (optional) the debugging:

Point the “Start external program” to the installed revit.exe.

Go to Tools – Options – Debugging, check “Use Managed Compatibility Mode”.

Set a break point in your code.

Press F5 in VS and Revit should be started.

Activate your plugin and you break point should be hit.

~~~~~~~~~~END of original post~~~~~~~~~~

~~~~~~~~~~Update 2015.5.15~~~~~~~~~~

GitHub: 

A GitHub repository is created, with the complete Test project for Revit 2016 API. The only thing you need to do is edit the Assembly line in the .addin file, and copy the file to your Revit Addins folder. You are welcome to download the code, and let me know if there are any questions and problems. Enjoy!

https://github.com/lezhangnet/RevitAPI

Reference:

As mentioned at the beginning of this post, the content in this post is as concise as possible. If you want more information, here is a tutorial from Autodesk Revit API documentation that contains more details. You may also find the other parts of the documentation to be useful when you try to dig dipper.

http://help.autodesk.com/view/RVT/2016/ENU/?guid=GUID-8EB25D2A-3CAF-486A-BA8E-C2BEF3DB68F6

“Customization could not be loaded” error with VSTO

ERROR: “Customization could not be loaded because the application domain could not be created.”

If you are working on an Excel (or other Office, I guess) VSTO AddIn / PlugIn project using C# and encountered this error, you may want to check that you are using the right platform (x86 vs x64) in your Configuration Manager.

I have x64 Office 2010 installed and saw this error when I am trying to run the x86 plugin today.

3-28-2014 4-17-19 PM

How to Debug/Run Navisworks 2013 API Programs

Of course you can just type in code, click build, go to Windows Explorer, copy your dll files to Plugins folder, start Navisworks and click the buttons on the Add-in tab. But what’s fun with that? Besides, that will not give you useful real-time info for debugging. Here in this blog I present you some simple configurations that can make your API life a little bit easier.

Use Post-build Event

Using post-build event to copy the generated dll file (and pdb file for debugging) to the destination folder in Plugins.

1. Right-click the project, choose Properties.

2. Click the Build Events tab on the left, copy the following to the “Post-build event command line”:

xcopy /Y “$(TargetDir)*.*” “C:\Program Files\Autodesk\Navisworks Manage 2013\Plugins\$(TargetName)\”

The “xcopy” is a Windows command for copying stuff. The “/Y” is a switch that tells the system to overwrite anything in the destination folder without letting the user confirm.

The $(Xyz) are macros that will be replaced by actually values. For example, on my machine it will be replaced as “xcopy /Y “D:\zhangle\BIM\Navisworks\API\myVsProjects\LeZhangPlugin\LeZhangPlugin\bin\Debug\*.*” “C:\Program Files\Autodesk\Navisworks Manage 2013\Plugins\LeZhangPlugin\””. Using the macros are good for code portability and ease to read and understand. If your Navisworks is not installed at the default folder, you need to adjust the destination folder accordingly. If you want to know all the macros, you may want to click the “Edit Post-build …” button, and click the “Macros” button.

Configure Start Action

If you just click the “Start” button in VS just like you are doing for any stand-alone application, VS will show you the following error message. Indeed, what we have created is a “Class Library” project, which generates a dll file. We need somehow trigger Navisworks first and run our program in it.

navi-1

1. Right-click your project name in the Solution Explorer, and click Properties, which is at the bottom of the pop-up menu.

2. Click Debug tab on the left; in Start Action group, choose “Start external program”. Click the browse button to go to Navisworks installation folder, and choose “Roamer.exe”. (I have no idea about the name, but trust me.) Save and close the project properties page.

3. In the code you want to run and debug, find an interesting statement and click the left side border of the code window as shown below. A red dot should be added as a “break point”, which means when running, the program will stop BEFORE running this statement to give you a chance to look into the status of the program.

navi-2

4. Click the Start button in VS again. Navisworks should start automatically.

5. Do something that will trigger your break point code. You will notice that your program will stop at the statement, while you can check the program status and use the different debug tools.

navi-3

Keep these in mind if a strange bug appears

Check which .NET framework you are using. Right-click your project – Properties. Make sure the “Target framework” is selected as .NET Framework 4. Since VS2012 uses .NET 4.5 as the default framework, some strange bugs may be as a result of the compatibility between different .NET framework versions. In one of my VS2012 project using Autodesk.Navisworks.Automation.dll, the assembly can be added into the reference without errors, but when running it throws “FileNotFoundException” on the Automation file. Changing the framework back to 4 then works fines.

NOTE: This is a re-post due to broken links on website transfer. The original link to this page is: http://lezhang.net/2012/06/29/how-to-debugrun-navi​sworks-2013-api-programs/

Pursuing IT with eager feet …