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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:44:48+00:00 2026-06-08T13:44:48+00:00

I have a AfterBuild target that I would like to use for multiple projects

  • 0

I have a AfterBuild target that I would like to use for multiple projects in a solution. Is there a way that I can put that target into a .targets file and reference the file in each project.

Below is what I tried which does not seem to work.

Project File:

<Import Project="..\debug.targets"/>

.Targets File:

    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AfterBuild">
    <PropertyGroup>
        <WebsiteDirectory>C:\Inetpub\wwwroot</WebsiteDirectory>
    </PropertyGroup>

    <ItemGroup>
        <output Include=".\**\*.dll" Exclude=".\**\obj\**" />
        <output Include=".\**\*.pdb" Exclude=".\**\obj\**" />
        <output Include=".\**\*.svc" />
        <output Include=".\**\*.xap" />
        <output Include=".\**\*.aspx" />
        <output Include=".\**\*.js" />
        <output Include=".\**\*.config" />
    </ItemGroup>

    <PropertyGroup>
        <VirtualDirectoryPath>$(WebsiteDirectory)\$(RootNamespace)</VirtualDirectoryPath>
    </PropertyGroup>

    <copy SourceFiles="@(output)" DestinationFiles="@(output->'$(VirtualDirectoryPath)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>

  • 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-06-08T13:44:49+00:00Added an answer on June 8, 2026 at 1:44 pm

    Use this

    <Import Project="$(MSBuildThisFileDirectory)\debug.targets"/> 
    

    $(MSBuildThisFile) = The current project file.
    $(MSBuildThisFileDirectory) = The directory that contains current project file.

    Relative paths in project files are difficult to use depending on what is invoking the project file. Using msbuild directly and the relative path will resolve to the project file. Use VS and the relative path will use the solution file as the base path.

    Using $(MSBuildThisFileDirectory) will force the relative path to use a pre-determined beginning path. All you need to do is fill in the rest of the relative path.

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

Sidebar

Related Questions

I use VS 2010 I would like at the pressing of Build Button have
I have a C# project where I run ILMerge in the AfterBuild target. However,
I have a .sln solution file that references a .csproj project file that has
I have a project with this in its MSBuild script: <Target Name=AfterBuild> <GenerateBootstrapper ApplicationFile=MyApp.msi
I have a solution with several web application projects in it. After all the
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I have defined several AfterBuild - Tasks in my Visual Studio project with different
I have a couple of different solutions, in which some projects may depend on
I have a post-build target in MSBuild to copy some build outputs. This is
I have a solution with a lot of project, Default build configuration manager is

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.