HMR
HMR

Reputation: 39270

Create project from "open website"

I am using Visual Studio 2012 Express. Have a bunch of aspx and cs files of a website that needs changing. No project file at all.

For the last days I have spent hours and hours trying to make this work but about to give up on this and tell the client that without a project file this isn't possible. Can hardly believe that is the case but can't figure out how to even re compile these files.

In VS there is an option file => open web site. In the solution explorer right clicked the solution and added a class library project. Moved the code in App_code to there and compiled it.

Created a new asp.net empty web forms application, copied all the files in the project directory. Added reference to the DLL created by the class library project.

When I choose compile every reference in a code behind file to a control like Label1.Text produces an error "The name 'Label1' does not exist in the current context". In the solution explorer the code behind shows when expanding the aspx file and they are "included in project"

There is an option to right click the aspx => convert to web application.

It still is complaining about references that are right there (in usercontrols) and before in App_Code.

Is there a step by step way of doing this that actually works? Most of the steps provided by Microsoft end up in a state that won't even compile.

Upvotes: 1

Views: 100

Answers (2)

HMR
HMR

Reputation: 39270

Got it to compile in the end and could now use sql server express and "publish"

Here is what I did:

Created an empty web application and copied files from the site that doesn't have a project file (can only be opened with open website).

First added referenced to the dll files in the bin directory (solution explorer => right click references and browse to bin folder of the empty web application).

Then click on the "Show all fies" button in the solution explorer. Right clicked App_Code => include in project.

Compiled the project (need to do this before adding other stuff).

Start adding other folders to project like the UserControls folder and compile each time I added them.

At the end added all the aspx and cs files in root and compiled again without an error.

One more importaint thing I found out today trying to add a C# web form is that the empty web application I've created was a VB application and I added c# files to it.

When creating an empty c# web application and adding the c# files to it the errors return. As soon as I try to compile any user controls by including them. It complains about objects in the ascx file "not available in this context" from the code behind.

Upvotes: 1

Chuck Conway
Chuck Conway

Reputation: 16435

You can just leave it as a "Website". Websites compile on the server and do not need to be compiled before deployment. I've been on projects where the site would not compile as a whole, the company was content making changes to each file. I don't know if this is the case with your site or not.

In general when converting a "website" to a web application all you need to do is add the .aspx files and the corresponding .cs file. Then select "Convert to Web application" as you mentioned in the question. This does not always work and as you've found out it won't compile. The only solution I know of is to manually fix the error. A lot of the times its simply adding the control definition to the .designer.cs file.

Upvotes: 1

Related Questions