Link to home
Start Free TrialLog in
Avatar of davisnw
davisnw

asked on

How to include common aspx pages into different Web Application Projects?

Hi,  I have two separate web applications which include many common aspx pages.  I would like to separate the common pages into a single directory which are then referenced by the two Web Application Projects, rather than having actual copies.

I can easily share simple class files across the projects by simply adding references.  However, that does not seem to work for aspx pages.  How can I do this?
Avatar of davisnw
davisnw

ASKER

One thing I have tried is adding the following to the .csproj file of the separate web applications:

  <ItemGroup>
    <Compile Include="..\Gateway.Common\index.aspx">
      <Link>index.aspx</Link>
    </Compile>
    <Compile Include="..\Gateway.Common\index.aspx.cs">
      <Link>index.aspx.cs</Link>
      <SubType>ASPXCodeBehind</SubType>
      <DependentUpon>index.aspx</DependentUpon>
    </Compile>
    <Compile Include="..\Gateway.Common\index.aspx.designer.cs">
      <Link>index.aspx.designer.cs</Link>
      <DependentUpon>index.aspx</DependentUpon>
    </Compile>
  </ItemGroup>

However, although the files then show up in the project (as links) I get strange errors:

Error      1      Keyword, identifier, or string expected after verbatim specifier: @      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      1      3      Gateway.AdminView
Error      2      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      6      88      Gateway.AdminView
Error      3      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      7      97      Gateway.AdminView
Error      4      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      20      81      Gateway.AdminView
Error      5      Preprocessor directives must appear as the first non-whitespace character on a line      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      22      74      Gateway.AdminView
Error      6      A namespace does not directly contain members such as fields or methods      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      1      1      Gateway.AdminView
Error      7      Keyword, identifier, or string expected after verbatim specifier: @      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      1      3      Gateway.BorrowerView
Error      8      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      6      88      Gateway.BorrowerView
Error      9      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      7      97      Gateway.BorrowerView
Error      10      Newline in constant      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      20      81      Gateway.BorrowerView
Error      11      Preprocessor directives must appear as the first non-whitespace character on a line      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      22      74      Gateway.BorrowerView
Error      12      A namespace does not directly contain members such as fields or methods      C:\Documents and Settings\davisn.NMEAF\Desktop\Copy of GatewayTrunk\src\Gateway.Common\index.aspx      1      1      Gateway.BorrowerView

These errors are not due to errors in the page, because the page works fine when added directly rather than as a link.
Can you try adding the aspx from another project by using Add Existing Item? Lets see if it creates a new copy for itself or tries to share the same physical file
Avatar of davisnw

ASKER

Add Existing Item creates a copy.  What I need is for it to share the same physical file.
Why not add a link to the other web page from the Menu ?
Avatar of davisnw

ASKER

Because these two applications are published on different servers - one internal and one external.  Also, the unique pages of the individual applications need to share session state with the common files.  Thus the common files actually need to be part of the Web Application Project, but linked to the same file for development purposes.
I dont think it is possible to reference to the same physical files from two different projects. Even if the IDE lets us point to another physical directory it would defy all rules of security, session sharing, deployment in my opinion.
Avatar of davisnw

ASKER

To be clear, it is only needing to reference the same physical file during development for the purposes of maintaining the same common codebase.  At deployment, copies of the common files will be deployed to their separate directories.
Even during development all these rules would apply and thats the reason i think it is not possible
ASKER CERTIFIED SOLUTION
Avatar of davisnw
davisnw

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of davisnw

ASKER

BTW: another neat trick I discovered:

In order to edit the csproj files with full Intellisense, do the following:

Right click on the Project and select "Unload Project"
Right click on the Project agian and select "Edit Project"
When done editing, Right click on the project and select "Reload Project"
Avatar of davisnw

ASKER

One other part of the solution that I forgot to mention:

In order for you to be able to debug the individual applications within the IDE, you may find it necessary to add a process to copy the appropriate web.configs from their individual configuration directories to the root application directory.  The links will take care of publishing, but they don't seem to get processed for a build within the IDE.

For example:

<Target Name="BeforeBuild">
   <Copy SourceFiles="..\App1Config\Web.config;..\App1Config\App1Authentication.config;..\App1Config\App1AppSettings.config;..\App1Config\App1Connections.config" DestinationFolder=".\" />
</Target>
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator