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

  • SEARCH
  • Home
  • 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 4002868
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:04:57+00:00 2026-05-20T08:04:57+00:00

Suppose I add a custom target to a csproj file. Is there a way

  • 0

Suppose I add a custom target to a csproj file. Is there a way to run that target from visual studio? I don’t want it make it a prebuild or postbuild step, I just want to be able to run this target (and its dependencies) from visual studio.

  • 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-20T08:04:58+00:00Added an answer on May 20, 2026 at 8:04 am

    There is a simple way (though not all that satisfying) using a custom external tool.

    Assuming your project file has the following modification:

      <Target Name="CalledFromIde">
        <Error Text="Called from the IDE!" />
      </Target>
    

    Go to Tools | External Tools and add one like this:

      Title:      Called from IDE
      Command:    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
      Arguments:  $(ProjectDir)$(ProjectFileName) /t:CalledFromIde
      Initial directory:  $(ProjectDir)
      Use Output window:  checked
    

    Running this produces output as:

      Build FAILED.
    
      "F:\Code\CsProject\CsProject.csproj" (CalledFromIde target) (1) ->
      (CalledFromIde target) -> 
        F:\Code\CsProject\CsProject.csproj(57,5): error : Called from the IDE!
    

    What you are doing is calling out to MSBuild as an external tool and having it run the target directly. You have to supply the full path to MSBuild because the IDE doesn’t maintain the same properties that the build environment it creates has available.

    You can hook this up to a shortcut by figuring out which command # it is in the set Tools.ExternalCommand#.

    If you’re looking for a solution with more sophistication, it is a bit more involved. Here it is in a nutshell (for VS2010):

    1) Create a VS Addin (File | New | Project | Other Project Types | Extensibility | Visual Studio Add-in). I’m not sure if you have to have the VS SDK installed to get this, it is available in the extension manager.

    Select the following options in the wizard:
    – Microsoft Visual Studio 2010
    – Yes, create a ‘Tools’ menu item
    – Load when the Application starts
    – My Add-in will never put up modal UI, and can be used with command line builds.

    2) Add references to Microsoft.Build and Microsoft.Build.Framework

    3) Find the implementation of Exec in the Connect.cs file

    4) Replace it with this code:

    public void Exec(
        string commandName,
        vsCommandExecOption executeOption,
        ref object varIn,
        ref object varOut,
        ref bool handled)
    {
        handled = false;
        if (executeOption != vsCommandExecOption.vsCommandExecOptionDoDefault)
            return;
        if (commandName != "BuildAddin.Connect.BuildAddin")
            return;
    
        var doc = _applicationObject.ActiveDocument;
        var projectItem = doc.ProjectItem;
        var project = projectItem.ContainingProject;
        var evalProject =
            Microsoft.Build.Evaluation.ProjectCollection
            .GlobalProjectCollection.LoadProject(project.FullName);
        var execProject = evalProject.CreateProjectInstance();
    
        bool success = execProject.Build("CalledFromIde", null);
    
        var window = _applicationObject.Windows.Item(Constants.vsWindowKindOutput);
        var output = (OutputWindow)window.Object;
        OutputWindowPane pane = output.OutputWindowPanes.Add("BuildAddin");
        pane.OutputString(success ? "built /t:CalledFromIde" : "build failed");
    
        handled = true;
        return;
    }
    

    5) A better custom target while debugging, since the previous one errors:

      <Target Name="CalledFromIde">
        <WriteLinesToFile File="CalledFromIde.txt" Lines="Called from the IDE!" />
      </Target>
    

    6) The code above has no error checking for brevity, you’ll want to be much cleaner since it will be running in the IDE. The addin will place a menu item on your Tools menu. As written above, it simply looks for the project containing the currently active editor document, which would need some better plumbing for whatever you are cooking up.

    This technique gets the build engine instance from within the IDE and has it execute a build on a separate instance of the project.

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

Sidebar

Related Questions

Is there any Visual Studio Add-In that can do the remove method refactoring? Suppose
Suppose we start from scratch in Visual Studio 2010 and add a 'WCF Service
Suppose I have a Python class that I want to add an extra property
Suppose you want to add an extra layer of credentials on top of a
Suppose you want to dynamically add to a HTML menu, where the menu HTML
I have a List that looks like this List<custom> this_list = new List<custom>(); this_list.Add(new
Suppose I have a custom collection class that provides some internal thread synchronization. For
Suppose I got an external library bst that handles custom data types insertion in
Is there an easy way to change the default method that a particular HTTP
Suppose you have a file that contains IP addresses, one address in each line:

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.