Blogger Widgets
  • Sharing Photos using SignalR
  • TFS Extenstion - allows copy work items between projects
  • Displaying jquery progressbar with ajax call on a modal dialog
  • Managing windows services of a server via a website
  • Exploring technologies available to date. TechCipher is one place that any professional would like to visit, either to get an overview or to have better understanding.

Search This Blog

Tuesday 20 November 2012

Unable to share user controls as a link between projects in ASP.NET

Sharing user control as a link between project is not advisable as per microsoft article How to: Add Existing Items to a Project. Look at note under "Adding an Existing Item as a Link" as it says

"Visual Basic Web projects, Visual C# Web projects, and other similar projects do not support links to items."

But if you still want to go with this method, then here it is how you can achieve it. Consider you have following projects in your solution
- Web application 1 => csharpbloggerapp.csproj
- Web application 2 => csharpblogtracker.csproj
- a deployment project for web app csharpbloggerapp.deploy.csproj (for csharpbloggerapp.csproj)

Now consider you have a script csharpcomm.js inside csharpblogtracker.csproj under script folder and would like to include this into csharpbloggerapp.csproj not as another file but as a link, so making changes/fixes/enhancements will be easy.

1. First go to "scripts" folder inside csharpbloggerapp.csproj, then right click on "Scripts" folder select "Add Existing Item" , browse to csharpblogtracker->scripts and select the file csharpcomm.js
2. Now from the Open button drop-down list, select Add As Link

After adding the link, compile your deploy project and you shall notice "csharpcomm.js" has not been copied.

3. Now add a "Post Build Event" for csharpbloggerapp.csproj as follows

xcopy /y $(ProjectDir)$(OutDir)..\..\csharpblogtracker\Scripts\csharpcomm.js $(ProjectDir)$(OutDir)..\Scripts
That's it... now compile your deployment project and you should find csharpcomm.js copied. Same procedure can be used for pages, user controls, resource files etc..

But correct method is to create a common assembly and add reference to this common library.

“We have to stop optimizing for programmers and start optimizing for users.” – Jeff Atwood

1 comments:

Copyright © 2013 Template Doctor . Designed by Malith Madushanka - Cool Blogger Tutorials | Code by CBT | Images by by HQ Wallpapers