Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1092893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:44:59+00:00 2026-05-16T23:44:59+00:00

I’ve created a custom VS template which uses an IWizard class to do some

  • 0

I’ve created a custom VS template which uses an IWizard class to do some automatic actions when a user creates a project to set project properties and paths, I’ve managed to set some project properties like build path by saving the .csproj file with parameters inside $ signs and setting those parameters in the replacementDictionary, during the RunStarted method.

Unfortunately I’m having trouble adding items as links to the .csproj using the same method. I have a .cs file I need to add as an existing and as a link item to each project created, it’s path would be determined by where the user chooses to save the project. I’ve got to the part where I know the path of the .cs file, (absolute and relative to the project’s path).

Here’s what I’ve tried so far:

  • Save the .csproj file with a section for the item, with placeholders for the path:
    <Compile Include="$path_to_cs_file\cs_file_name.cs$">
    <Link>$cs_file_name.cs$</Link>
    </Compile>

I’ve tried doing this with both absolute and relative paths, but this for some reason makes VS replace the path with a completely different relative path under Documents and Settings\user\Local Settings.

  • In RunStarted, cast the automationObject as DTE and call it’s ItemOperations.AddExistingItem method. Using either path results in errors (The parameter is incorrect).

  • In ProjectFinishedGenerating, save the project’s path, then at RunFinished, create a Microsoft.Build.BuildEngine.Project object with that path, call DTE commands to save all files and unload the project, then call the project object’s AddNewItem Method and SetMetaData on the resulting ProjectItem, afterwards I save the project and reload it with the DTE object, this, again results the same errors as before

I’d appreciate any help with the subject, I’m pretty much stumped. Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:45:00+00:00Added an answer on May 16, 2026 at 11:45 pm

    I managed to “solve” this issue, what I did is the following:

    • Kept the placeholder in the csproj, but never added the related parameters to the replacement dictionary:

      <Compile Include="$path_to_cs_file$\$cs_file_name.cs$">
      <Link>$cs_file_name.cs$</Link>
      </Compile>

    • At the ProjectFinishedGenerated method, unloaded the project, edited the csproj file to replace the paths, and reloaded the project:

      projectFileName = project.FullName
      // Unload file and manually add the linked item
      dte.ExecuteCommand("File.SaveAll");
      dte.ExecuteCommand("Project.UnloadProject"); // See Note Below
      StreamReader reader = new StreamReader(projectFileName);
      string content = reader.ReadToEnd();
      reader.Close();
      content = Regex.Replace(content, @"\$path_to_cs_file\$", ...);
      content = Regex.Replace(content, @"\$cs_file_name\$", ...);
      StreamWriter writer = new StreamWriter(projectFileName);
      writer.Write(content);
      writer.Close();
      dte.ExecuteCommand("Project.ReloadProject");

    Note: The above code assumes the project needed modifying is currently selected project, usually when ProjectFinishedGenerating runs this is the case, however in a multi-project template or if you’ve added a project manually to the solution this might not be the case, you’ll have to call dte methods to choose your “main” project in the project explorer, then go on with unloading, editing, and reloading. The code to do so would look something like this:
    UIHierarchy UIH = dte2.ToolWindows.SolutionExplorer;
    UIHierarchyItem UIHItem = UIH.UIHierarchyItems.Item(1);
    UIHItem.UIHierarchyItems.Item(testProjectName).Select(vsUISelectionType.vsUISelectionTypeSelect);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.