I'm using Visual Studio 2008. I've added a control on a page but can't reference it in code-behind file. When I looked at the Code-Gen file, I didn't find my new control. It looks like Visual Studio didn't update Code Gen file to include my control. Is there a way to manually re-generate that Code Gen file?
If you want to refresh the designer file, you can create it like this:
Delete the [NameHere].aspx.designer.cs file.
Right click the [NameHere].aspx file.
Click Convert to Web Application.
Designer file is now re-created, or an error is thrown, letting you know what the issue is with the generation...given your case this is likely, but it'll let you know what to fix, then just click "Convert to Web Application" again once it's fixed.
Related
I took my WebForms project which was initially build using Visual Studio 2008 (!) and have converted it over to the "new style" Visual Studio project files, which has tremendously reduced the size of this file, and no longer explicitly names all files needed to build a project. This makes SCM merges much easier to manage conflicts due to file renames etc.
I asked this question about the conversion process,
Visual Studio is expanding wildcard project file includes upon build
However, since performing this upgrade, my .aspx edits no longer triggers a corresponding change to the .aspx.designer.vb and I have to make these edits manually, which is getting really frustrating.
Is this unsupported functionality (I realise that WebForms is very old technology now)? Before making the project file change then this was all working as expected.
The main change to the project file was to change the top-level element from
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
to
<Project Sdk="Microsoft.NET.Sdk">
UPDATE
Okay, it's definitely the project file. I created a new Web Forms "web application", and when modifying an ASPX page to add a new server-side control, the .designer.aspx.vb file was edited by Visual Studio automatically. I made the project file change detailed above and then edits made to the ASPX page are no longer reflected onto the .designer.aspx.vb file.
Nothing has changed in regards to you editing your aspx pages, and the system takes care of the desinger file(s).
I would make a backup, and consider then deleting the designer files. You can re-generate them by:
Click on the main project file, and then go from menu Project->convert to Web application.
Keep in mind that this will force/change all pages to be converted to code behind. So, if some pages are a mix code files + code behind (all pages will be converted code behind. That assumes a aspx page, and then a designer page). And I believe that if you using custom controls - that can be messed up.
So, no, you should not be messing with or have to touch or maintain the designer files. It is possible that something else here is messed up.
A discussion on re-creating designer files, and how do to this it outlined here:
Regenerate designer.cs
I am taking over an ASP.NET Web Application using C# and all the code (including C# source) was given to me without the solution file (something.sln) so whenever opening the Web Application in Visual Studio 2017 I have to open by "Folder..." instead of by "Project/Solution...". Once open, I am able to make the necessary changes to the code behind files such as Default.aspx.cs or somethingElse.aspx.cs, but when I try to test the code changes by going to Run > Start Without Debugging, I couldn't find the Run menu option; I see the Build Solution button but it's disabled (greyed out).
Every time I try navigating directly to my site at http://dev.mydomain.com. The code changes I made did not get compiled neither.
So how do I get the Run or Build menu option enabled?
The easiest way to correct this issue is probably to create a new, empty ASP.NET WebForms project (and a new solution file as well if necessary) and copy your code files into it. You can then tell Visual Studio to "include" those files in the project.
You may (or may not) need to make the odd other minor adjustment too but those basic steps should get you started.
Not sure if this is related, but adding the sln file to the git ignore removed its visibility from VisualStudio. I had to open the project csproj file in VisualStudio.
THen on close, the prompt was asking me to save a new SLN file with the same solution name i was looking for. I was then able to go to the directory with the original solution in it, and then I was able to open it again in Visual Studio.
For all those who come to this post in the future, I would check your gitignore files and see if they ignored the sln file.
i have 4 project in my solution, framework , domain objects,business objects and website ...
but this morning website project couldnt be loaded... when i tried firsttime to open solution... "The solution file has been modified outside the enviroment" message seemed and press reload then error is project file is corrupted... how can it happen... how can i fix this...
thx..
One way... if its from some source control , get the latest and leave the changed part by you.
If you dont have any source control then you can have the two options
- Create a new solution and add all your projects to it and rebuild it. Check for the errors.
- If your code is completely corrupted and files are unreadable, that is unrecoverable,
then you must have to follow this
copy the projects dlls out of bin
dir,
use red gate reflector and extract
all the class file in new project
file.
Now for aspx.cs you can create a new
project add all aspx file in that new project and also the
new cs files generated by the reflector addin. Do it for all pages. When done , right click on Project of web app(if its), then choose convert to web application. Also check the Page header of each page that they are using the same class files.
I know this is little bit tough , but will work....to recover almost that much code, when your app was last compiled.
Note : Also you will have to maintain the hierarchy of the project as the reflector add in (FileGenerator on Codeplex) might miss the actual project hierarchy.
You can open your solution file (.sln) in notepad and check for the consistency of the document.
The sln file will be in a hierarchical structure (like we have an xml).
You can also open csproj files of different projects that you have in the solution check the xml of the csproj.
I have a web app that has an app_offline.htm file, this file is stored in source control along with everything else.
The problem I have is that each time I (or any other developer) do a get latest on the source I get the app_offline.htm file and then when I try to run the app all I see is the app_offline rather than the actual web site.
Is there way that I can stop this from happening?
You can right click on the file and choose exclude from project. It renames the file so you IIS won't pick it up, but I'm pretty sure that Visual Studio will not remember that after you do a new checkout. (Can't verify this though)
Other than renaming it or removing it locally, it most certainly depends on your source control system. The whole point of source control is to "restore" a code source to a specific point. Checking out something other than the current state is kind of against the source controls principle..
Can you perhaps rename the file in source control and when you publish it you rename it to app_offline.htm then instead?
I am using SqlMetal to general my DataContext.dbml class for my ASP.net application using LinqToSql. When I initially created the DataContext.dbml file, Visual Studio used this to create a related DataContext.designer.cs file. This designer file contains the DataContext class in C# that is used throughout the app (and is derived from the XML in the dbml file) and is essential to bridging the gap between the output of SqlMetal and using the DataContext with LinqToSql.
However, when I make a change to the database and recreate the dbml file, the designer file never gets regenerated in my website. Instead, the old designer file is maintained (and therefore none of the changes to the DBML file are accessible through the LinqToSql DataContext class).
The only process I have been able to use so far to regenerate the designer file is
Go to Windows Explorer and delete both the dbml and designer.cs files
Go to Visual Studio and hit Refresh in the Solution Explorer. The dbml and designer.cs files now disappear from the project.
Regenerate the dbml file using SqlMetal
Go to Visual Studio and hit Refresh in the Solution Explorer. Now the designer.cs file is recreated.
It seems that Visual Studio will only generate the designer.cs file when a new dbml file is detected that does not yet have a designer.cs file. This process is pretty impractical, since it involves several manual steps and messes things up with source control.
Does anyone know how I can get the designer.cs file automatically regenerated without having to follow the manual delete/refresh/regenerate/delete process outlined above?
The designer.cs file is normally maintained automatically as you make changes to the DBML within Visual Studio. If VS isn't running when you recreate the DBML it may not know.
Check that the .DBML file in Visual Studio has Custom Tool property set to MSLinqToSQLGenerator. If it isn't, then set it to that. If it is try right-clicking on the DBML after making changes and choosing Run Custom Tool to see if that updates the .designer.cs.
You can also generate the class file using SqlMetal:
sqlmetal /code:DataContext.designer.cs /language:csharp DataContext.dbml
Not sure how It did it, but here are some things I worked on to get it back.
Something had it locked, so it generated a new db.designer.cs file (db1.designer.cs).
I had beyond compare open, comparing that file to the previous one (BC isn't supposed to lock and I don't think it was the problem, never had that problem before with it.)
Open the project file in notepad and look for these entries, i revereted to the previous version in source control..
this is what i brought back.
<Compile Include="db.designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>db.dbml</DependentUpon>
</Compile>
...
<LastGenOutput>db.designer.cs</LastGenOutput>
the lastgenOutput was set to db1.desginer.cs