Reusable UserControl Library in ASP.NET 2.0 RC1

G

Guest

In a blog from Scott Guthrie
(http://weblogs.asp.net/scottgu/archive/2005/08/28/423888.aspx) I found a
sample to build a UserControl Library inside one ASP.NET project and then
deploy it to other projects and reuse it.
He suggests that you "publish" the web site to a directory and include this
directory into your (second) web site. I tried this but VS (and the
aspnet_compiler) complains that my user control now is implemented twice.
When I remove the "aspx" files and only copy the compiled dlls I cannot
access the user controls for they are not found.
Unfortunately, Scotts sample doesnt go into details about how to include
these UserContorls into new web sites.
So the question is:
If I have the compiled user control (e.g.
"App_Web_MyUserControl.ascx.12345678.dll") copied into the new web site, how
can I reference the control therein in my page ?

Guenter from Frankfurt/Germany
 
G

Guest

Hi Scott,

the article read great, but I coudn't manage to get it to work yet.
(I am running on RC1, BUild 50727)

Problems are many:
* first, I had to recognize that ILMerge is not an intrinsic part of the
..net framework (ok, one who can identify and follow links in your post
clearly has an advantage :)
* then, the TempDirectory variable is not declared by default, I had to
insert a <PropertyGroup>
* and now the persisting problem: my Temp Directory contains spaces, and I
can't get MSBuild to surround the dll names with quotes (seems that the
<CreateItem does not offer this feature)

Is there a way around that ?

Guenter
 
S

Scott Allen

Hmm - my temp directory and project directory avoid spaces in the
names. I'd have to experiement with MSBuild a little more.
 
G

Guest

Hi Scott,

after playing around with MSBuild for awhile, I have modified your build
configuration and have achieved the following:
* the build process can cope with blanks (at least inside the "temp" path)
* the build process only rebuilds the target if files are changed
* a "clean" cleans the temp directory
There's just one or thing missing (maybe you've got an ieas for that):
I explicitly have to reference the DLL file inside the webb app; just
erferencing the project does not do. There must be some information inside
the project file that tells VisualStudio which files are to be copied as part
of the build processs, but I can't figure out where that information lives.

For your records, this is how my build file looks now:

<PropertyGroup>
<ILMergeEXE>"$(ProgramFiles)\Microsoft\ILMerge\ILMerge.exe"</ILMergeEXE>
<TempDirectory>$(Temp)\MSBuildTemp</TempDirectory>
</PropertyGroup>
<Target Name="PrecompiledAssemblies" Inputs="@(Compile)"
Outputs="$(TempDirectory)\PrecompiledApp.config">
<AspNetCompiler Debug="false" PhysicalPath="$(MSBuildProjectDirectory)"
TargetPath="$(TempDirectory)" Updateable="false" Force="true"
VirtualPath="$(MSBuildProjectName)" />
</Target>
<Target Name="SingleDll" DependsOnTargets="PrecompiledAssemblies"
Outputs="$(OutputPath)\$(MSBuildProjectName).dll"
Inputs="$(TempDirectory)\PrecompiledApp.config">
<CreateItem Include="$(TempDirectory)\bin\*.dll">
<Output ItemName="PrecompiledAssemblies" TaskParameter="Include" />
</CreateItem>
<Exec Command="$(ILMergeEXE)
/out:$(OutputPath)\$(MSBuildProjectName).dll /targetplatform:v2
%22@(PrecompiledAssemblies, '%22 %22')%22" />
</Target>
<Target Name="AfterClean">
<RemoveDir Directories="$(TempDirectory)" />
</Target>
(I hobe this survives the post...)

Feel free to use it, maybe even to update your blog entry (I would feel
proud about that :)

Guenter
 
S

Scott Allen

There's just one or thing missing (maybe you've got an ieas for that):
I explicitly have to reference the DLL file inside the webb app; just
erferencing the project does not do. There must be some information inside
the project file that tells VisualStudio which files are to be copied as part
of the build processs, but I can't figure out where that information lives.

That's another area that I could not tidy up to the point I would like
it. I've been hesitant to spend anymore time with it at this date
because I know the ASP.NET team is releasing a merge and deplyoment
tool around RTM, so I want to wait and see what that tool looks like.
Feel free to use it, maybe even to update your blog entry (I would feel
proud about that :)

Sure thing :) I'm going to add a reference to this post in the
comments for people to find.
 
Joined
Jul 26, 2006
Messages
1
Reaction score
0
My Newer Solution

I've just posted a new solution for .Net 2 that allows you to include UserControls, Pages and MasterPages in a single Web Application Project library that can be distrubed easily.

Its quick and easy to set up, there a description of how it works and a solution download that demonstrates everything working.

http://www.nearasmakesnomatter.co.uk/wapul.htm

Graham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top