· Asp.Net

Sharing Resources Between Asp.Net projects

If you need to share resources such as images and javascript files between different Asp.Net projects, an easy way to do it is to:

  • Move the assets in a common location.

  • Right click on project and choose “Add Existing Item”

  • Navigate to shared resources and click on “Add As Link”

  • Open your project file in a text editor and update the “AfterBuild” Target.

      <Target Name="AfterBuild">
          <!-- Delete old copies of linked files -->
          <Delete Condition=" '%(Content.Link)' != '' AND Exists('$(WebProjectOutputDir)\%(Content.Link)') " Files="$(WebProjectOutputDir)\%(Content.Link)" />
          <!-- Copy linked files -->
          <Copy Condition=" '%(Content.Link)' != '' " SourceFiles="%(Content.Identity)" DestinationFiles="$(WebProjectOutputDir)\%(Content.Link)" />
      </Target>

This makes sure that the linked content is copied while maintaining the folder structure.