locked
Can't get basic VS 2010 add-in project to work RRS feed

  • Question

  • I've created loads of add-ins in VS 2005 and 2008, and they all work with some minor adjustments in VS 2010.  But I'm having difficulty creating even a simple add-in from scratch in VS 2010.  I've tried on two different machines, both are running windows 7 64-bit and VS 2010 Professional.  Here's the steps I'm going through:

    1.  New->Project

    2.  Other Project types->extensibility->Visual Studio Add-In

    3.  Create add-in using Visual C#

    4.  Set application host to VS 2010 only (uncheck macros option)

    5.  Check "create a tools menu item", and check "Load add-in when VS starts"

    6.  Finish wizard

    7.  Compile and run

    My first problem is that the generated code doesn't even compile.  The compiler complains that contextGUIDs is an object[], and it cannot convert ref contextGUIDs to ref System.Array.  This is weird because when I look at one of my working add-ins (that were converted from VS 2008), it passes ref contextGUIDs, which is declared as an object[], to that same method and it compiles fine.  Both projects target .NET 4.0, and both are calling EnvDTE.Command.AddNamedCommand2, which is defined in the EnvDTE80 assembly...I must be missing something obvious.  Anyway, this is easily fixed by changing the definition of contextGUIDs to Array contextGUIDs = new object[] {};

    Now that my project compiles, I try running it.  VS 2010 gives me the 80070002 error, "The System Cannot find the file specified" error.  I double check the .addin file in my /documents/Visual Studio 2010/Addins/ folder, the file it's referencing is c:\dev\MyAddin1\MyAddin1\bin\MyAddin1.dll, and that file does exist.  I double check by starting VS again while running process monitor, and all attempts to access this file are successful.

    You can download the project here - This is exactly what VS generated, no extra code except the change described above to make it compile:

    http://www.phelpscomputing.com/MyAddin1.zip

    And the .addin file from the Addins directory is here:

    http://www.phelpscomputing.com/MyAddin1%20-%20For%20Testing.AddIn

    Thanks in advance for any help you can give me...I feel so ineffective without being able to make addins for every little thing I don't want to do manually :-)

    Tuesday, July 13, 2010 6:32 PM

Answers

  • Hello Jaredhite1,

    This is a known issue with Visual Studio 2005 (Beta 2). For more information, please refer to Addin Wizard on Visual Studio 2005 (Beta 2) . But I can't reproduce this issue in Visual Studio 2010.

    If you use Visual Studio Addin Project Template to generate code, the Embed Interop Types of Envdte.dll is False by default in Visual Studio 2010. So I guess there is something wrong with your Visual Studio 2010, please try to restall your Visual Studio 2010.

    Best Regards,
    Nancy


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Jaredhite1 Monday, July 19, 2010 7:12 PM
    Thursday, July 15, 2010 8:16 AM

All replies

  • OK, I think I've got the main bit solved, it looks like in VS 2010 the default output folder is bin/debug/, and in 2008 it was just bin/.  So modifying my .addin file to point to bin/debug/ made the add-in work correctly.  However, I'm still uncertain as to why the .addin file VS creates incorrectly points to bin/ and not bin/debug, why the code the VS wizard creates doesn't compile, why the compiled .dll existed in /bin, and why VS couldn't find it.  However, since my addin is working now those questions are just for curiosity's sake.
    Tuesday, July 13, 2010 8:18 PM
  • Hi Jaredhite,

    first: i can't open your archive. WinRar states that the file is corrupt.

    Anyway i tried to reproduce your problem but everything runs fine on my machine (same envrionment W7/x64 english). Did you have any prerelease version von VS 2010 installed. Maybe there is some old project template floating arround.

    The magic of having the file in bin\ additionally to bin\debug is a manually edited project file. Open your MyAddin1.csproj file with a text editor and have look on the target. There you will find the following: 

    <Target Name="AfterBuild">
    ...
    <Copy Condition="Exists('$(OutputPath)$(DllName)')" SourceFiles="$(OutputPath)$(DllName)" DestinationFolder="$(DeploymentDirectory)">
    <
    Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
    </
    Copy>
    ...
    </Target>

    DeploymentDirectory is defined as .\bin\ at the beginning of the build file. I think that explains the behaviour

    Ralf

    <

    Tuesday, July 13, 2010 11:00 PM
  • Hi Ralias-

    Thanks for your response.  I've fixed the .zip archive, it should open correctly now.  It's odd that it works fine for you in the same environment...But I guess if this were happening to many other people I would have found more information on it on the net.  About a week ago I reformatted and reinstalled windows on both of the machines, and VS 2010 is the only VS version ever to have been on either of them.

    I do see those lines in my .csproj file...I guess it's probably always been that way but I never noticed that the files were being copied to both places.  

    Tuesday, July 13, 2010 11:42 PM
  • Hmm, thats strange. I see that the contextGuids are declared as Array in your project instead of object[] in mine. Anyway i can compile your project without errors. Do you use an english version of visual studio? Perhaps the project template has a problem in other languages only.

    BTW: The after build target copy tasks are in your project file.

    Wednesday, July 14, 2010 12:31 AM
  • Yes, I changed the declaration to be an Array instead of an object[], because object[] wouldn't compile for me.  If you change it back to an object[] does it compile for you?

    I'm using an english version of VS.

    Wednesday, July 14, 2010 3:40 AM
  • Yes, it does
    Wednesday, July 14, 2010 4:39 AM
  • It's a mystery to me, then.  Here's a screenshot of it failing to compile for me.

    http://www.phelpscomputing.com/Capture.jpg

    Edit:  It looks like the broken projects that VS 2010 generates reference a different EnvDTE80.dll than the working VS 2010 projects that I converted from 2008, and the signature of that method is slightly different between the two assemblies.

    Wednesday, July 14, 2010 4:44 AM
  • Hi Jared,

    i think i can explain the compiler problem. If I look into your project references the assemblies EnvDTE and EnvDTE80 are referenced from the output location:

    E:\download\temp\MyAddin1\MyAddin1\MyAddin1\obj\Debug\Interop.EnvDTE.dll
    E:\download\temp\MyAddin1\MyAddin1\MyAddin1\obj\Debug\Interop.EnvDTE80.dll

    In my project the assemblies are referenced from the GAC

    C:\Windows\assembly\GAC\EnvDTE\8.0.0.0__b03f5f7f11d50a3a\EnvDTE.dll
    C:\Windows\assembly\GAC\EnvDTE80\8.0.0.0__b03f5f7f11d50a3a\EnvDTE80.dll

    The references in your project are created if you add the DTE assemblies from the .NET tab. If I do so i can reproduce the your problem. Can you remove the references and add the following two from the COM tab?

    Microsoft Development Environment 8.0 (Version 7.0 Object Model)
    Microsoft Development Environment 8.0

    The next good question is how you got this project setup. Did you install some software that modified the visual studio project templates?

    Ralf

    Wednesday, July 14, 2010 5:14 AM
  • Huh...It's actually the opposite for me.  If I add them from the .NET tab and set "Embed Interop Types" to false, object[] compiles fine.  If I add them from the COM tab, I get the error message in my screenshot.

    I'm pretty sure I haven't installed anything that messes with the templates.  It's a vanilla VS installation, no add-ins, extensions, or plug-ins except the ones I've written myself.

    Wednesday, July 14, 2010 7:07 PM
  • Hello Jaredhite1,

    This is a known issue with Visual Studio 2005 (Beta 2). For more information, please refer to Addin Wizard on Visual Studio 2005 (Beta 2) . But I can't reproduce this issue in Visual Studio 2010.

    If you use Visual Studio Addin Project Template to generate code, the Embed Interop Types of Envdte.dll is False by default in Visual Studio 2010. So I guess there is something wrong with your Visual Studio 2010, please try to restall your Visual Studio 2010.

    Best Regards,
    Nancy


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Jaredhite1 Monday, July 19, 2010 7:12 PM
    Thursday, July 15, 2010 8:16 AM
  • I just double check that. It behaves as I said. May the answer of Nancy explains the reason. I also looks to me if your visual studio installation is somehow screwed up.
    Thursday, July 15, 2010 1:18 PM
  • Interesting.  I'm not sure that reinstalling my VS would help, since I see exactly the same behavior on both of my computers.  More likely the version of VS that I downloaded from Microsoft's DreamSpark program is messed up somehow.  Perhaps I'll try redownloading and reinstalling and see if that helps.  Thanks Ralias and Nancy for helping me with this.  Even if it doesn't work at least I know a little more about the problem and I can successfully work around it.  

    As a side-note, my new add-in works great now...It's a little thing that emulates the F5 functionality in SQL Server Management Studio.  It compiles and runs only the highlighted C# code and if applicable, sends its output to a new output window.  I love VS add-ins.

    Monday, July 19, 2010 7:12 PM