Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reusable UserControl Library in ASP.NET 2.0 RC1

21 views
Skip to first unread message

Guenter at dot

unread,
Oct 19, 2005, 7:35:02 AM10/19/05
to
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

Scott Allen

unread,
Oct 19, 2005, 11:04:50 AM10/19/05
to
One technique I've been exloring is using MSBuild and ILMerge to
produce a truely reusable assembly of user controls:

http://odetocode.com/Blogs/scott/archive/2005/10/06/2326.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

Guenter at dot

unread,
Oct 20, 2005, 4:47:04 AM10/20/05
to
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

Scott Allen

unread,
Oct 20, 2005, 8:28:24 AM10/20/05
to
Hmm - my temp directory and project directory avoid spaces in the
names. I'd have to experiement with MSBuild a little more.

--
Scott
http://www.OdeToCode.com/blogs/scott/

Guenter at dot

unread,
Oct 20, 2005, 10:40:23 AM10/20/05
to
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

Scott Allen

unread,
Oct 20, 2005, 12:35:21 PM10/20/05
to
On Thu, 20 Oct 2005 07:40:23 -0700, "Guenter"
<gtschech(at)hotmail(dot)com> wrote:


>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.

--
Scott
http://www.OdeToCode.com/blogs/scott/

0 new messages