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 6546359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:41:52+00:00 2026-05-25T11:41:52+00:00

I want to create a nuget package that adds a BeforeBuild step to my

  • 0

I want to create a nuget package that adds a BeforeBuild step to my csproj using a custom MSBuild task I have created. Ideally, I want to:

  1. Add a new Target into the csproj file (MyCustomBeforeBuildTarget)
  2. Add the BeforeBuild target if it is not already there
  3. Edit the BeforeBuild DependsOnTargets attribute to include my custom target

So after install my csproj should have the following in:

<Target Name="MyCustomBeforeBuildTarget" Condition="SomeCondition">
     <MyCustomTask />
</Target>
<Target Name="BeforeBuild" DependsOnTargets="MyCustomBeforeBuildTarget">

</Target>

Also, it would be nice that when my package is removed, the custom target disappears too,
although I have added a condition that should make it ignore the target if my custom task DLL is not present.

What is the simplest Powershell nuget install script I can write that will add my custom target? I have a feeling that the PowerShell scripts here might form part of the solution, but I don’t have enough PowerShell experience to know how to actually use them to edit the csproj.

  • 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-25T11:41:53+00:00Added an answer on May 25, 2026 at 11:41 am

    The NuGetPowerTools is a package that adds some PowerShell functions that makes it easier to work with the project setup of the project you’re adding a package to. To use the functions available you only need to make your package depend on the NuGetPowerTools, using the dependencies tag in your packages nuspec file like this:

    <dependencies>
      <dependency id="NuGetPowerTools" version="0.26" />
    </dependencies>
    

    This will make it possible to grab a reference to a build project representation of your project.

    Then you need to put an install.ps1 file in the tools folder of your NuGet package, this PowerShell file will run when you install the package and never again after installation.

    The file should look something like this:

    #First some common params, delivered by the nuget package installer
    param($installPath, $toolsPath, $package, $project)
    
    # Grab a reference to the buildproject using a function from NuGetPowerTools
    $buildProject = Get-MSBuildProject
    
    # Add a target to your build project
    $target = $buildProject.Xml.AddTarget("PublishWebsite")
    
    # Make this target run before build
    # You don't need to call your target from the beforebuild target,
    # just state it using the BeforeTargets attribute
    $target.BeforeTargets = "BeforeBuild"
    
    # Add your task to the newly created target
    $target.AddTask("MyCustomTask")
    
    # Save the buildproject
    $buildProject.Save()
    
    # Save the project from the params
    $project.Save()
    

    That should be it.

    Regards

    Jesper Hauge

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

Sidebar

Related Questions

I plan to create some NuGet package that adds some library and some new
i want create a custom json data from the mssql 2008 results so that
I'm creating a nuget package that I want to be compatible for both MVC2
I want create an accordion control similar to one created using AJAX http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Accordion/Accordion.aspx where
I have installed StructureMap using Nuget . I do not want to checkin the
I want to use the SquishIt nuget package inside and MVC3 application that is
I want create wordpress website into which I want create user management... That means
i want create image animation , i have 50 images with png format now
I want to create a new field (or two) in my table that is
I want create a tarball that when extracted the file(s) will be placed at

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.