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
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.
Is there a way to have linked files in an ASP.NET 1.1 project?
What I did was to copy the linked file declaration from a DLL csproj to the file I want. But everytime I change the Web.csproj to add a new file, the links are deleted.
Is there a possible workaround? maybe inserting this in the build scripts or something like that?
Is this possible in .NET 2.0?
If you are using Visual Studio 2003 then linked files are not supported:
If you want to explicitly add an item as a link, you can create links
in the following projects:
The solution, Visual C++, and other similar projects support only links, so all of the items in these projects are links. The project
does not attach a link indicator (a small arrow) to the item icon in
Solution Explorer.
Visual Basic, Visual C#, and other similar projects can accommodate both linked and physical project items. Linked items in these projects
display a link indicator attached to the icons of linked project
items.
Visual Basic Web, Visual C# Web and other similar projects, do not
support links to items
http://msdn.microsoft.com/en-us/library/9f4t9t92(v=VS.71).aspx
You can work around this by creating a symbolic link (symlink) to the first instance of the file. The Link Shell Extension makes it easy to do so in Windows Explorer and it will even add an arrow badge to the file's icon (you have to use NTFS). Or use the command line program mklink:
> cd Project\Properties
> mklink AssemblyInfo.cs ..\..\Global\AssemblyInfo.cs
When you have created a symlink, it's as if the same file exists in both places. It's transparent to applications, including (I expect) Visual Studio 2003. This is not the same as a shortcut (.lnk file).
UPDATE: what I did in the end was to take another approach. I simply put a validation in my build script that if the csproj does not contain any reference to my AssemblyInfo files, the build failed.
This was ok because the only time they would be deleted, is when the csproj gets modified which is almost never.
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.
In our ASP.Net web project we seem to have some .refresh files associated with some of the 3rd party Dlls we're using. Any idea what they are and how/when they are created?
These files give the path to the DLL in question to tell Visual Studio where to find it (you can check this if you open them in a text editor). They will be created each time you add a new reference to the project.
They normally appear when you are using a project type that does not create a standard Visual Studio project file, as normally paths to referenced DLLs would go in there.
From here:
In an ASP.NET project, adding a file-based reference will add a .refresh file in the Bin folder. When the project is under source control, this file is then added to source control. *.dll.refresh files that litter the bin directory. Every time you add an external reference, you'll find a dll.refresh file right next to it. These dll.refresh files are an exception to the rule, and they should go into source control. Its the only way your web project will know where its references live.
Some information about the refresh files after trial and error. These experiments were done with Visual Studio 2012. The references were added to a C# asp.net web project.
As was discussed, adding a reference to an assembly through browse adds a .refresh file. However, if there are additional dependent DLL's on the explicitly added DLL in the directory that you add from, the dependents are implicitly added as well, but without .refresh files! So for example, I add a reference to "MyAssembly.dll" I will get also "MyAssembly.dll.refresh". But if there is an assembly "MyDependentAssembly.dll" that "MyAssembly.dll" depends on I will not get a "MyDependentAssembly.dll.refresh". So what happens is that the one assembly is refreshed but not its dependents! You must add the DLLs one at a time in reverse order of dependency and then things will work better.
Some other things to be careful of.
Adding "MyAssembly.dll" will also add "MyAssembly.pdb" if it is present. Also "MyAssembly.xml" will be added to the references if it is present. Those two files will refresh too when "MyAssembly.dll.refresh" is present.
But, when does Visual Studio decide to look for refresh files? Now remember, in a web project, the project file does not keep track of referenced DLL's specifically. You will not find the DLL's listed in the project file only project dependencies. So when does the refresh happen?
The answer to when refresh happens is during a build when the referenced assembly has to be loaded. That means, though that building a prebuilt updateable website may not grab all of the DLLs. I kept having a DLL that would not refresh and then I realized it was being used only inside of a .ascx file. Unchecking the "Allow precompiled site to be updateable" checkbox in the MSBuild Options project page fixed that problem for me.
Still if you add referenced DLLs that are loaded through reflection in your code, they will not be updated through a reference. You will have to use build events to copy them into the bin directory.