Question on - Automatic compilation of VB.NET files on a Web Server

M

Microsoft News

Not sure if this is the correct newsgroup. Could be the IIS. Hopefully
someone can answer my question.

We are migration an ASP Web App to VB.NET. One of the benefits we're
enjoying so far with ASP is that we do not have to worry about a build
release. When an ASP file is modified and tested, we just deploy that file
to the production Web server through Visual SourceSafe without worrying that
we are releasing someone elses untested/unfinished code out.

Now I am hoping that .NET provides the same scenario where all we need to do
is copy the .aspx and .vb files to the Web Server, and all the .vb files
would automatically get compiled into the assembly when an .aspx file is
requested. Meaning that we wouldn't have to compile the application into a
DLL assembly. The environment would recognize that the .vb file has changed
and would get compiled into the existing assembly.

My question, does .NET work this way?

Thank you.
 
S

Scott M.

ASP.NET does not work this way. Classic ASP worked on interpreted, not
compiled code and that's why you were able to just copy the new file to the
web server and that was it.

First of all in ASP.NET, you aren't going to deploy ANY of your .vb files to
your production server at all. Files that end in .vb are your uncompiled
source code files and you would never want those sitting on your production
machine. Prior to deployment, you will do a "Release" build of all your
source code. This will take all the code in all the .vb files and compile
them into an ASP.NET assembly (.dll).

You then deploy all the .aspx files and the compiled assembly (.dll) to your
production server (along with any other supporting files you may have). The
assembly belongs in a direct sub-folder of your project called "bin" and
this is where VS.NET will create it in the first place on your development
server.

If, at a later date, you need to change ANY of your code in the .vb files,
you will need to re-compile and re-deploy the new assembly.
 
B

Brock Allen

Yes, ASP.NET does this for you. VS.NET on the other hand doesn't like this
model. VS.NET prefers that you precompile all of the codebehind files (.vb
files) prior to deploying tot he webserver. So you end up deploying ASPX
files and DLL files (no .VB files). But it's ok, you can alter this behavior
if you want to.

The trick to chaning this behavior is to change the CodeBehind attribute
in the ASPX to be Src. Src asks ASP.NET to compiled the referenced .vb file.
This is an unfortunate PITA of working with VS.NET -- it wants to do things
its way. Now if you're comfortable with compiling all the .vb files into
a DLL and deploying that instead of live .vb files, then you'll get along
better with VS.NET.

It's also possible to not use VS.NET at all. The other compelling tool is
WebMatrix[1] and it's much more in the style of deployment you've described,
meaning it doesn't compile the codebehind files. The major drawback with
WebMartix is that there is no intellisense support. HTH

[1] http://www.asp.net/webmatrix/default.aspx?tabIndex=4&tabId=46

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
M

Microsoft News

Thank you. This led me in a correct direction. I found the following help
docs in MSDN.

----<Begin>
The Codebehind, Inherits, and Src Attributes
In Web Forms that use code-behind files, the @ Page directive (or @ Control
in user control files) contains attributes that specify the relationship of
the .aspx file and its code-behind file. These attribute are:

a.. Codebehind In Visual Studio, this attribute references the name of a
file that contains the class for the page. For example, if you create a Web
Forms page in Visual Studio called WebForm1, the Codebehind attribute will
point to WebForm1.aspx.vb or WebForm1.aspx.cs. This attribute is used only
by the Visual Studio Web Forms Designer. It tells the designer where to find
the page class so that the designer can create an instance of it for you to
work with. The attribute is not used at run time.
b.. Inherits Identifies the class from which the page derives. In Visual
Studio, this points to a class in the project assembly (.dll), as shown in
the diagram above.
The code-behind model illustrated above is the model used by Visual Studio.
The ASP.NET Framework supports a slightly different code-behind model for
Web Forms pages. In the ASP.NET code-behind model, the visual elements are
in an .aspx file and the code is in a separate code-only file, as in Visual
Studio. However, there is no project, and the code is not pre-compiled.
Instead, the code in the .vb or .cs file is compiled at run time, when the
page is first requested by a user.

The inheritance model works as illustrated above, with the difference that
the Web Forms class (WebForm1 class in the diagram) is not part of a project
assembly. Instead, each page is a separate assembly. There is no difference
in how your code runs in the two models.

In the ASP.NET code-behind model, there is no Codebehind page attribute,
since that attribute is unique to Visual Studio. To tie the .aspx file to
its corresponding code, the page directive contains a Src attribute, which
references the file containing the source code for the file.

The Src attribute is not supported in Visual Studio. If you import a Web
Forms page into Visual Studio that contains the Src attribute, the designer
will raise an error. For details, see The file could not be loaded into the
Web Forms designer.

-----<End>



Now I just need to test if VS.NET will support both attributes 'CodeBehind'
and 'Src' on the same page so I can get the benefit of the VS designer and
the JIT functionality.

I will post my results tomorrow, as I am heading home.



===========================================================



Brock Allen said:
Yes, ASP.NET does this for you. VS.NET on the other hand doesn't like this
model. VS.NET prefers that you precompile all of the codebehind files (.vb
files) prior to deploying tot he webserver. So you end up deploying ASPX
files and DLL files (no .VB files). But it's ok, you can alter this behavior
if you want to.

The trick to chaning this behavior is to change the CodeBehind attribute
in the ASPX to be Src. Src asks ASP.NET to compiled the referenced .vb file.
This is an unfortunate PITA of working with VS.NET -- it wants to do things
its way. Now if you're comfortable with compiling all the .vb files into
a DLL and deploying that instead of live .vb files, then you'll get along
better with VS.NET.

It's also possible to not use VS.NET at all. The other compelling tool is
WebMatrix[1] and it's much more in the style of deployment you've described,
meaning it doesn't compile the codebehind files. The major drawback with
WebMartix is that there is no intellisense support. HTH

[1] http://www.asp.net/webmatrix/default.aspx?tabIndex=4&tabId=46

-Brock
DevelopMentor
http://staff.develop.com/ballen


Not sure if this is the correct newsgroup. Could be the IIS. Hopefully
someone can answer my question.

We are migration an ASP Web App to VB.NET. One of the benefits we're
enjoying so far with ASP is that we do not have to worry about a build
release. When an ASP file is modified and tested, we just deploy that
file to the production Web server through Visual SourceSafe without
worrying that we are releasing someone elses untested/unfinished code
out.

Now I am hoping that .NET provides the same scenario where all we need
to do is copy the .aspx and .vb files to the Web Server, and all the
.vb files would automatically get compiled into the assembly when an
.aspx file is requested. Meaning that we wouldn't have to compile the
application into a DLL assembly. The environment would recognize that
the .vb file has changed and would get compiled into the existing
assembly.

My question, does .NET work this way?

Thank you.
 
M

Microsoft News

Ok, a follow up question, plz.

We now have .vb component files that do not have any corresponding .aspx
pages to them. Would they also go through the JIT compilation when a method
is called on them?

ie.

/Logon.aspx
/Logon.aspx.vb --> calls Security.Authenticate(UserID)
/Components/BAL/Security.vb --> calls SecurityDB.Authenticate(UserID)
/Components/DAL/SecurityDB.vb --> Retreives data from a DB using Stored
Proc.

Now, will SecurityDB.vb and Security.vb also get compiled and executed like
Logon.aspx.vb would with the Src attribute in Logon.aspx?

Thanks again.



Brock Allen said:
Yes, ASP.NET does this for you. VS.NET on the other hand doesn't like this
model. VS.NET prefers that you precompile all of the codebehind files (.vb
files) prior to deploying tot he webserver. So you end up deploying ASPX
files and DLL files (no .VB files). But it's ok, you can alter this behavior
if you want to.

The trick to chaning this behavior is to change the CodeBehind attribute
in the ASPX to be Src. Src asks ASP.NET to compiled the referenced .vb file.
This is an unfortunate PITA of working with VS.NET -- it wants to do things
its way. Now if you're comfortable with compiling all the .vb files into
a DLL and deploying that instead of live .vb files, then you'll get along
better with VS.NET.

It's also possible to not use VS.NET at all. The other compelling tool is
WebMatrix[1] and it's much more in the style of deployment you've described,
meaning it doesn't compile the codebehind files. The major drawback with
WebMartix is that there is no intellisense support. HTH

[1] http://www.asp.net/webmatrix/default.aspx?tabIndex=4&tabId=46

-Brock
DevelopMentor
http://staff.develop.com/ballen


Not sure if this is the correct newsgroup. Could be the IIS. Hopefully
someone can answer my question.

We are migration an ASP Web App to VB.NET. One of the benefits we're
enjoying so far with ASP is that we do not have to worry about a build
release. When an ASP file is modified and tested, we just deploy that
file to the production Web server through Visual SourceSafe without
worrying that we are releasing someone elses untested/unfinished code
out.

Now I am hoping that .NET provides the same scenario where all we need
to do is copy the .aspx and .vb files to the Web Server, and all the
.vb files would automatically get compiled into the assembly when an
.aspx file is requested. Meaning that we wouldn't have to compile the
application into a DLL assembly. The environment would recognize that
the .vb file has changed and would get compiled into the existing
assembly.

My question, does .NET work this way?

Thank you.
 
B

Brock Allen

You can add an <%@ Assembly Src="YourOtherFile.vb" %> to the page to have
ASP.NET compile it. Otherwise ASP.NET doesn't know about it. In ASP.NET 2.0
there's a special App_Code directory specifically for this purpose.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Ok, a follow up question, plz.

We now have .vb component files that do not have any corresponding
.aspx pages to them. Would they also go through the JIT compilation
when a method is called on them?

ie.

/Logon.aspx
/Logon.aspx.vb --> calls Security.Authenticate(UserID)
/Components/BAL/Security.vb --> calls SecurityDB.Authenticate(UserID)
/Components/DAL/SecurityDB.vb --> Retreives data from a DB using
Stored
Proc.
Now, will SecurityDB.vb and Security.vb also get compiled and executed
like Logon.aspx.vb would with the Src attribute in Logon.aspx?

Thanks again.

Yes, ASP.NET does this for you. VS.NET on the other hand doesn't like
this model. VS.NET prefers that you precompile all of the codebehind
files (.vb files) prior to deploying tot he webserver. So you end up
deploying ASPX files and DLL files (no .VB files). But it's ok, you
can alter this
behavior

if you want to.

The trick to chaning this behavior is to change the CodeBehind
attribute in the ASPX to be Src. Src asks ASP.NET to compiled the
referenced .vb
file.

This is an unfortunate PITA of working with VS.NET -- it wants to do
things

its way. Now if you're comfortable with compiling all the .vb files
into a DLL and deploying that instead of live .vb files, then you'll
get along better with VS.NET.

It's also possible to not use VS.NET at all. The other compelling
tool is WebMatrix[1] and it's much more in the style of deployment
you've
described,

meaning it doesn't compile the codebehind files. The major drawback
with WebMartix is that there is no intellisense support. HTH

[1] http://www.asp.net/webmatrix/default.aspx?tabIndex=4&tabId=46

-Brock
DevelopMentor
http://staff.develop.com/ballen
Not sure if this is the correct newsgroup. Could be the IIS.
Hopefully someone can answer my question.

We are migration an ASP Web App to VB.NET. One of the benefits we're
enjoying so far with ASP is that we do not have to worry about a
build release. When an ASP file is modified and tested, we just
deploy that file to the production Web server through Visual
SourceSafe without worrying that we are releasing someone elses
untested/unfinished code out.

Now I am hoping that .NET provides the same scenario where all we
need to do is copy the .aspx and .vb files to the Web Server, and
all the .vb files would automatically get compiled into the assembly
when an .aspx file is requested. Meaning that we wouldn't have to
compile the application into a DLL assembly. The environment would
recognize that the .vb file has changed and would get compiled into
the existing assembly.

My question, does .NET work this way?

Thank you.
 
M

Microsoft News

Ok..another stumbling block ... grrrrrr

The <%@ Assembly ... %> page directive only works if the class name is
referenced on that same .aspx page.
Trying to call a method in MySecurity.vb from Default.aspx.vb will not work.
Is there a way to make this work without having to compile MySecurity.vb
into an assembly?
Here's the source I wrote using WebMatrix editor for a quick test that
produces an error.

Files:
C:/Projects/Sandbox/Default.aspx
C:/Projects/Sandbox/Default.aspx.vb
C:/Projects/Sandbox/Components/BLL/MySecurity.vb

The following line in Default.aspx.vb breaks:
---> Dim Result As MySecurity = New Sandbox.MySecurity

I would really like to be able to make this scenario work. Is it possible?

Thank you again :D

SOURCE CODE

<---Start Default.aspx page
<%@ Page Language="VB" Src="Default.aspx.vb" Inherits="_Default" %>
<%@ Import Namespace="Sandbox.BLL" %>
<%@ Assembly Src="Components/BLL/MySecurity.vb" %>

<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</p>
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Calendar id="Calendar1" runat="server" BackColor="White"
Width="200px" DayNameFormat="FirstLetter" ForeColor="Black" Height="180px"
Font-Size="8pt" Font-Names="Verdana" BorderColor="#999999" CellPadding="4">
<TodayDayStyle forecolor="Black"
backcolor="#CCCCCC"></TodayDayStyle>
<SelectorStyle backcolor="#CCCCCC"></SelectorStyle>
<NextPrevStyle verticalalign="Bottom"></NextPrevStyle>
<DayHeaderStyle font-size="7pt" font-bold="True"
backcolor="#CCCCCC"></DayHeaderStyle>
<SelectedDayStyle font-bold="True" forecolor="White"
backcolor="#666666"></SelectedDayStyle>
<TitleStyle font-bold="True" bordercolor="Black"
backcolor="#999999"></TitleStyle>
<WeekendDayStyle backcolor="#FFFFCC"></WeekendDayStyle>
<OtherMonthDayStyle
forecolor="#808080"></OtherMonthDayStyle>
</asp:Calendar>
</p>
<p>
<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</p>
</form>
</body>
</html>
<---End Default.aspx page


<---Start Default.aspx.vb
Imports System

Public Class _Default
Inherits System.Web.UI.Page

Protected Label1 As System.Web.UI.WebControls.Label
Protected TextBox1 As System.Web.UI.WebControls.TextBox
Protected Calendar1 As System.Web.UI.WebControls.Calendar
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

Public Sub New()
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostback() Then
Label1.Text = "YooHoo"
End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim Result As MySecurity = New Sandbox.MySecurity

Label1.Text = "Hello, " & TextBox1.Text & "! Welcome on " &
Calendar1.SelectedDate & "." & "You have been - " & Result.Authenticate(0)
End Sub

End Class
<---End Default.aspx.vb

<---Start MySecurity.vb
Imports System

Namespace Sandbox.BLL
Public Class MySecurity
Public Sub New()
End Sub

Public Function Authenticate(ByVal UserID As Int32) As String
Return "Authenticated"
End Function
End Class
End Namespace
<---End MySecurity.vb



Brock Allen said:
You can add an <%@ Assembly Src="YourOtherFile.vb" %> to the page to have
ASP.NET compile it. Otherwise ASP.NET doesn't know about it. In ASP.NET 2.0
there's a special App_Code directory specifically for this purpose.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Ok, a follow up question, plz.

We now have .vb component files that do not have any corresponding
.aspx pages to them. Would they also go through the JIT compilation
when a method is called on them?

ie.

/Logon.aspx
/Logon.aspx.vb --> calls Security.Authenticate(UserID)
/Components/BAL/Security.vb --> calls SecurityDB.Authenticate(UserID)
/Components/DAL/SecurityDB.vb --> Retreives data from a DB using
Stored
Proc.
Now, will SecurityDB.vb and Security.vb also get compiled and executed
like Logon.aspx.vb would with the Src attribute in Logon.aspx?

Thanks again.

Yes, ASP.NET does this for you. VS.NET on the other hand doesn't like
this model. VS.NET prefers that you precompile all of the codebehind
files (.vb files) prior to deploying tot he webserver. So you end up
deploying ASPX files and DLL files (no .VB files). But it's ok, you
can alter this
behavior

if you want to.

The trick to chaning this behavior is to change the CodeBehind
attribute in the ASPX to be Src. Src asks ASP.NET to compiled the
referenced .vb
file.

This is an unfortunate PITA of working with VS.NET -- it wants to do
things

its way. Now if you're comfortable with compiling all the .vb files
into a DLL and deploying that instead of live .vb files, then you'll
get along better with VS.NET.

It's also possible to not use VS.NET at all. The other compelling
tool is WebMatrix[1] and it's much more in the style of deployment
you've
described,

meaning it doesn't compile the codebehind files. The major drawback
with WebMartix is that there is no intellisense support. HTH

[1] http://www.asp.net/webmatrix/default.aspx?tabIndex=4&tabId=46

-Brock
DevelopMentor
http://staff.develop.com/ballen
Not sure if this is the correct newsgroup. Could be the IIS.
Hopefully someone can answer my question.

We are migration an ASP Web App to VB.NET. One of the benefits we're
enjoying so far with ASP is that we do not have to worry about a
build release. When an ASP file is modified and tested, we just
deploy that file to the production Web server through Visual
SourceSafe without worrying that we are releasing someone elses
untested/unfinished code out.

Now I am hoping that .NET provides the same scenario where all we
need to do is copy the .aspx and .vb files to the Web Server, and
all the .vb files would automatically get compiled into the assembly
when an .aspx file is requested. Meaning that we wouldn't have to
compile the application into a DLL assembly. The environment would
recognize that the .vb file has changed and would get compiled into
the existing assembly.

My question, does .NET work this way?

Thank you.
 
B

Brock Allen

You need to then build these additional files into an assembly (a DLL, in
essence) and deploy it to the ~/bin directory. You'll have a much easier
time of it. You can use the command line compiler. Mine is here, but it will
be different on your machine:

c:\WINDOWS\Microsoft.NET\Framework\v2.0.41202\vbc.exe

And so then run:

vbc /t:library /out:MyLib.dll MyFile.vb MyFile2.vb MyFile3.vb

Then copy MyLib.dll into your ~/bin directory. Anything in the ~/bin is automatically
visible (and referenced) by the ASPX pages.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Ok..another stumbling block ... grrrrrr

The <%@ Assembly ... %> page directive only works if the class name is
referenced on that same .aspx page.
Trying to call a method in MySecurity.vb from Default.aspx.vb will not
work.
Is there a way to make this work without having to compile
MySecurity.vb
into an assembly?
Here's the source I wrote using WebMatrix editor for a quick test that
produces an error.
Files:
C:/Projects/Sandbox/Default.aspx
C:/Projects/Sandbox/Default.aspx.vb
C:/Projects/Sandbox/Components/BLL/MySecurity.vb
The following line in Default.aspx.vb breaks:
---> Dim Result As MySecurity = New Sandbox.MySecurity
I would really like to be able to make this scenario work. Is it
possible?

Thank you again :D

SOURCE CODE

<---Start Default.aspx page
<%@ Page Language="VB" Src="Default.aspx.vb" Inherits="_Default" %>
<%@ Import Namespace="Sandbox.BLL" %>
<%@ Assembly Src="Components/BLL/MySecurity.vb" %>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</p>
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Calendar id="Calendar1" runat="server"
BackColor="White"
Width="200px" DayNameFormat="FirstLetter" ForeColor="Black"
Height="180px"
Font-Size="8pt" Font-Names="Verdana" BorderColor="#999999"
CellPadding="4">
<TodayDayStyle forecolor="Black"
backcolor="#CCCCCC"></TodayDayStyle>
<SelectorStyle backcolor="#CCCCCC"></SelectorStyle>
<NextPrevStyle verticalalign="Bottom"></NextPrevStyle>
<DayHeaderStyle font-size="7pt" font-bold="True"
backcolor="#CCCCCC"></DayHeaderStyle>
<SelectedDayStyle font-bold="True" forecolor="White"
backcolor="#666666"></SelectedDayStyle>
<TitleStyle font-bold="True" bordercolor="Black"
backcolor="#999999"></TitleStyle>
<WeekendDayStyle
backcolor="#FFFFCC"></WeekendDayStyle>
<OtherMonthDayStyle
forecolor="#808080"></OtherMonthDayStyle>
</asp:Calendar>
</p>
<p>
<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</p>
</form>
</body>
</html>
<---End Default.aspx page
<---Start Default.aspx.vb
Imports System
Public Class _Default
Inherits System.Web.UI.Page
Protected Label1 As System.Web.UI.WebControls.Label
Protected TextBox1 As System.Web.UI.WebControls.TextBox
Protected Calendar1 As System.Web.UI.WebControls.Calendar
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Public Sub New()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostback() Then
Label1.Text = "YooHoo"
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles
Button1.Click
Dim Result As MySecurity = New Sandbox.MySecurity
Label1.Text = "Hello, " & TextBox1.Text & "! Welcome on " &
Calendar1.SelectedDate & "." & "You have been - " &
Result.Authenticate(0)
End Sub
End Class
<---End Default.aspx.vb
<---Start MySecurity.vb
Imports System
Namespace Sandbox.BLL
Public Class MySecurity
Public Sub New()
End Sub
Public Function Authenticate(ByVal UserID As Int32) As String
Return "Authenticated"
End Function
End Class
End Namespace
<---End MySecurity.vb

You can add an <%@ Assembly Src="YourOtherFile.vb" %> to the page to
have ASP.NET compile it. Otherwise ASP.NET doesn't know about it. In
ASP.NET
2.0

there's a special App_Code directory specifically for this purpose.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Ok, a follow up question, plz.

We now have .vb component files that do not have any corresponding
.aspx pages to them. Would they also go through the JIT compilation
when a method is called on them?

ie.

/Logon.aspx
/Logon.aspx.vb --> calls Security.Authenticate(UserID)
/Components/BAL/Security.vb --> calls
SecurityDB.Authenticate(UserID)
/Components/DAL/SecurityDB.vb --> Retreives data from a DB using
Stored
Proc.
Now, will SecurityDB.vb and Security.vb also get compiled and
executed
like Logon.aspx.vb would with the Src attribute in Logon.aspx?
Thanks again.


Yes, ASP.NET does this for you. VS.NET on the other hand doesn't
like this model. VS.NET prefers that you precompile all of the
codebehind files (.vb files) prior to deploying tot he webserver.
So you end up deploying ASPX files and DLL files (no .VB files).
But it's ok, you can alter this

behavior

if you want to.

The trick to chaning this behavior is to change the CodeBehind
attribute in the ASPX to be Src. Src asks ASP.NET to compiled the
referenced .vb

file.

This is an unfortunate PITA of working with VS.NET -- it wants to
do

things

its way. Now if you're comfortable with compiling all the .vb files
into a DLL and deploying that instead of live .vb files, then
you'll get along better with VS.NET.

It's also possible to not use VS.NET at all. The other compelling
tool is WebMatrix[1] and it's much more in the style of deployment
you've

described,

meaning it doesn't compile the codebehind files. The major drawback
with WebMartix is that there is no intellisense support. HTH

[1] http://www.asp.net/webmatrix/default.aspx?tabIndex=4&tabId=46

-Brock
DevelopMentor
http://staff.develop.com/ballen
Not sure if this is the correct newsgroup. Could be the IIS.
Hopefully someone can answer my question.

We are migration an ASP Web App to VB.NET. One of the benefits
we're enjoying so far with ASP is that we do not have to worry
about a build release. When an ASP file is modified and tested, we
just deploy that file to the production Web server through Visual
SourceSafe without worrying that we are releasing someone elses
untested/unfinished code out.

Now I am hoping that .NET provides the same scenario where all we
need to do is copy the .aspx and .vb files to the Web Server, and
all the .vb files would automatically get compiled into the
assembly when an .aspx file is requested. Meaning that we wouldn't
have to compile the application into a DLL assembly. The
environment would recognize that the .vb file has changed and
would get compiled into the existing assembly.

My question, does .NET work this way?

Thank you.
 
M

Microsoft News

Thx Brock for your responses.
It sounds like I will not be able to do what I wanted with VS.NET and
ASP.NET, which was to mimic the non-compile/no DLLs production environment.
Looks like some form of compilation of certain files in the application will
be required. Physical DLL files will have to be rolled out.

Again, thanks for your quick reponses. Maybe the next version of .NET will
provide what we're looking for.

Until then...happy coding!
-sandor




Brock Allen said:
You need to then build these additional files into an assembly (a DLL, in
essence) and deploy it to the ~/bin directory. You'll have a much easier
time of it. You can use the command line compiler. Mine is here, but it will
be different on your machine:

c:\WINDOWS\Microsoft.NET\Framework\v2.0.41202\vbc.exe

And so then run:

vbc /t:library /out:MyLib.dll MyFile.vb MyFile2.vb MyFile3.vb

Then copy MyLib.dll into your ~/bin directory. Anything in the ~/bin is automatically
visible (and referenced) by the ASPX pages.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Ok..another stumbling block ... grrrrrr

The <%@ Assembly ... %> page directive only works if the class name is
referenced on that same .aspx page.
Trying to call a method in MySecurity.vb from Default.aspx.vb will not
work.
Is there a way to make this work without having to compile
MySecurity.vb
into an assembly?
Here's the source I wrote using WebMatrix editor for a quick test that
produces an error.
Files:
C:/Projects/Sandbox/Default.aspx
C:/Projects/Sandbox/Default.aspx.vb
C:/Projects/Sandbox/Components/BLL/MySecurity.vb
The following line in Default.aspx.vb breaks:
---> Dim Result As MySecurity = New Sandbox.MySecurity
I would really like to be able to make this scenario work. Is it
possible?

Thank you again :D

SOURCE CODE

<---Start Default.aspx page
<%@ Page Language="VB" Src="Default.aspx.vb" Inherits="_Default" %>
<%@ Import Namespace="Sandbox.BLL" %>
<%@ Assembly Src="Components/BLL/MySecurity.vb" %>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:Label id="Label1" runat="server">Label</asp:Label>
</p>
<p>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Calendar id="Calendar1" runat="server"
BackColor="White"
Width="200px" DayNameFormat="FirstLetter" ForeColor="Black"
Height="180px"
Font-Size="8pt" Font-Names="Verdana" BorderColor="#999999"
CellPadding="4">
<TodayDayStyle forecolor="Black"
backcolor="#CCCCCC"></TodayDayStyle>
<SelectorStyle backcolor="#CCCCCC"></SelectorStyle>
<NextPrevStyle verticalalign="Bottom"></NextPrevStyle>
<DayHeaderStyle font-size="7pt" font-bold="True"
backcolor="#CCCCCC"></DayHeaderStyle>
<SelectedDayStyle font-bold="True" forecolor="White"
backcolor="#666666"></SelectedDayStyle>
<TitleStyle font-bold="True" bordercolor="Black"
backcolor="#999999"></TitleStyle>
<WeekendDayStyle
backcolor="#FFFFCC"></WeekendDayStyle>
<OtherMonthDayStyle
forecolor="#808080"></OtherMonthDayStyle>
</asp:Calendar>
</p>
<p>
<asp:Button id="Button1" runat="server"
Text="Button"></asp:Button>
</p>
</form>
</body>
</html>
<---End Default.aspx page
<---Start Default.aspx.vb
Imports System
Public Class _Default
Inherits System.Web.UI.Page
Protected Label1 As System.Web.UI.WebControls.Label
Protected TextBox1 As System.Web.UI.WebControls.TextBox
Protected Calendar1 As System.Web.UI.WebControls.Calendar
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Public Sub New()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostback() Then
Label1.Text = "YooHoo"
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles
Button1.Click
Dim Result As MySecurity = New Sandbox.MySecurity
Label1.Text = "Hello, " & TextBox1.Text & "! Welcome on " &
Calendar1.SelectedDate & "." & "You have been - " &
Result.Authenticate(0)
End Sub
End Class
<---End Default.aspx.vb
<---Start MySecurity.vb
Imports System
Namespace Sandbox.BLL
Public Class MySecurity
Public Sub New()
End Sub
Public Function Authenticate(ByVal UserID As Int32) As String
Return "Authenticated"
End Function
End Class
End Namespace
<---End MySecurity.vb

You can add an <%@ Assembly Src="YourOtherFile.vb" %> to the page to
have ASP.NET compile it. Otherwise ASP.NET doesn't know about it. In
ASP.NET
2.0

there's a special App_Code directory specifically for this purpose.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Ok, a follow up question, plz.

We now have .vb component files that do not have any corresponding
.aspx pages to them. Would they also go through the JIT compilation
when a method is called on them?

ie.

/Logon.aspx
/Logon.aspx.vb --> calls Security.Authenticate(UserID)
/Components/BAL/Security.vb --> calls
SecurityDB.Authenticate(UserID)
/Components/DAL/SecurityDB.vb --> Retreives data from a DB using
Stored
Proc.
Now, will SecurityDB.vb and Security.vb also get compiled and
executed
like Logon.aspx.vb would with the Src attribute in Logon.aspx?
Thanks again.


Yes, ASP.NET does this for you. VS.NET on the other hand doesn't
like this model. VS.NET prefers that you precompile all of the
codebehind files (.vb files) prior to deploying tot he webserver.
So you end up deploying ASPX files and DLL files (no .VB files).
But it's ok, you can alter this

behavior

if you want to.

The trick to chaning this behavior is to change the CodeBehind
attribute in the ASPX to be Src. Src asks ASP.NET to compiled the
referenced .vb

file.

This is an unfortunate PITA of working with VS.NET -- it wants to
do

things

its way. Now if you're comfortable with compiling all the .vb files
into a DLL and deploying that instead of live .vb files, then
you'll get along better with VS.NET.

It's also possible to not use VS.NET at all. The other compelling
tool is WebMatrix[1] and it's much more in the style of deployment
you've

described,

meaning it doesn't compile the codebehind files. The major drawback
with WebMartix is that there is no intellisense support. HTH

[1] http://www.asp.net/webmatrix/default.aspx?tabIndex=4&tabId=46

-Brock
DevelopMentor
http://staff.develop.com/ballen
Not sure if this is the correct newsgroup. Could be the IIS.
Hopefully someone can answer my question.

We are migration an ASP Web App to VB.NET. One of the benefits
we're enjoying so far with ASP is that we do not have to worry
about a build release. When an ASP file is modified and tested, we
just deploy that file to the production Web server through Visual
SourceSafe without worrying that we are releasing someone elses
untested/unfinished code out.

Now I am hoping that .NET provides the same scenario where all we
need to do is copy the .aspx and .vb files to the Web Server, and
all the .vb files would automatically get compiled into the
assembly when an .aspx file is requested. Meaning that we wouldn't
have to compile the application into a DLL assembly. The
environment would recognize that the .vb file has changed and
would get compiled into the existing assembly.

My question, does .NET work this way?

Thank you.
 

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

Top