Answered Change vdproj properties programatically

  • Monday, September 03, 2007 9:57 AM
     
     

     

    Is it possible to change vdproj properties programatically?  I want to change them automatically as part of the build process, but the only way I've found of doing this is to open up the .vdproj file and manually alter the properties required (ie version number, product code, title etc) using regular expressions.  It's a bit of a clunky solution though and the changes don't always seem to be carrying through to the msi file either.

All Replies

  • Monday, September 03, 2007 10:14 AM
     
     

     

    sorry wrong part of the forum thats for vb this c#, we have the equivalent of cjproj and you have vbproj.

     

    but for what ur asking i also done know how to do that. but there is a way.

  • Monday, September 03, 2007 10:19 AM
     
     

     

    not vbproj, vdproj - setup project - in c#.
  • Monday, September 03, 2007 2:21 PM
     
     

     

    Okay, for anyone who's interested, I've got halfway there....

     

    using EnvDTE;

    ...

    ...

     

    EnvDTE.DTE visualStudio = (EnvDTE.DTE)Microsoft.VisualBasic.Interaction.CreateObject("VisualStudio.DTE.8.0", "");

    Solution sln = visualStudio.Solution;

    sln.Open("C:\\MySolution.sln");

    Projects projCollection = sln.Projects;

    for (int i = 1; i <= projCollection.Count; i++)

    {

    if (projCollection.Item(i).Name == "Setup1")

    {

    Console.WriteLine(projCollection.Item(i));

    projCollection.Item(i).Properties.Item("Title").Value ="New Value";

     

    break;

    }

    }

    sln.Close(true);

     

     

    This code works in that it changes the value of the Title property of the setup project.  But I also need to change the ProductCode property.

     

    projCollection.Item(i).Properties.Item("ProductCode").Value = new Guid();

     

    Throws an error, saying:

     

    "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"

     

    Any comments on how to improve the code (specifically how to get the project without looping through the collection) or how to set the productCode gratefully received.

  • Wednesday, September 05, 2007 8:05 AM
     
     Answered

    Hi CharlieWasAnangle,

     

    As I understand from your error message "Type mismatch", try to change your sample codes as follows and check if it works for you.

    projCollection.Item(i).Properties.Item("ProductCode").Value = (new Guid()).ToString();

     

    Hope this helps,

     

    Citizens on the earth

  • Monday, September 10, 2007 9:48 AM
     
     

     

    Thanks!
  • Thursday, June 10, 2010 3:34 PM
     
     

    Hello, 

    I have a problem related to this subject. I programatically change the property of the .vdproj, and I can see the result in the properties section (I use VS 2005) of the project, but the project does not save on build. For example, if I manually increment the Version, and then build, the setup project is automatically saved; but this does not happen if I increment the Version using the method described here ('programatically' in c#), even though the incremented version seems to appear in the msi. Did anyone else encountered this strange behaviour?