Typed DataSets in WebApplication Projects - asp.net

I am converting an older C# Website Project into a Web Application Project so that we can better manage it in our source control system. I have run into a problem.
The Website Project used strongly-typed-datasets (i.e. .XSD files). There is C# code written that uses these strongly typed datasets as an object. That worked fine when it was a Website Project but does NOT compile now that it is a Web Application project. The compiler can not find the reference to the datas set because datasets are not compiled.
Is there an easy solution to this problem?

You could use XSD.exe on the command line to generate the dataset classes into a class file and add the file to the new project.
xsd.exe StronglyTypedDataset.xsd /dataset
This will generate the file "StronglyTypedDataset.cs". Use the /namespace:My.Project.Namespace flag if you need to put the dataset classes into a specific namespace.
This is essentially what's going on behind the scenes in your website project.

There's a nice guide to integrate XSD compiler into Visual Studio (2003 - 2010). It might help you automate the process: http://wiki.codesynthesis.com/Using_XSD_with_Microsoft_Visual_Studio#Visual_Studio_2010_.2810.0.29

Another approach that worked for me when converting into a Web Application Project was to remove the .xsd file from the project and include it again.
VS 2008 automatically defined the "Custom Tool" property to use (MSDataSetGenerator) and re-creates the *.designer.cs file for me every time the xsd change.

Related

c# asp.net Centralized UI Development

We have a lot of websites with common functionality developed by 3 persons, in the business logic we use a common library project (in a shared directory) so we all use the same functions. This way the corrections and improvements are shared for the following projects or when we recompile an existing project. We have a class for some UI common functions too (loading a ListControl with x data and so)
The problem is with some web parts like CSS, Javascripts, Common Pages (login, configuration, customer management), those we don't know exactly how we can centralize them so we have those parts in the shared project so we don't have to copy paste corrections/improvements manually to the other websites each time...
Example of current website structure:
-MyWebSite1
-Styles.css
-Scripts.js
-Login.aspx
-Funx.cs (Functions specific to this site)
-Consx.cs (Session and other variables specific to this site)
-CommonProject (In a network shared directory)
-FunBusiness.cs
-FunWebUI.cs
-ConsBusiness.cs
-ConsWEB.cs
Is there a way of doing this?
For now the closest we have come to solving this problem is following this article for the Javascript part:
http://msdn.microsoft.com/en-us/library/bb398930(v=vs.100).aspx
We are now investigating using only one reference to a js file and including the other javascript references dinamically and the common CSS and MasterPages parts...
Maybe you can add those common references files as Linked File in Visual Studio. In this way you can maintain one file, while kept in a different location.
From Microsoft:
Link file leaves the file in its current location and maintains a link to the file from your current project.
Another solution would be to create a copy script before compile in Visual Studio. Reference over here.

Can't upgrade from MVC2 to MVC3

I've got myself an MVC2 web applicatin using .NET Framework 4 and am following these instructions to the T. However at step 10 when I save the updated ProjectTypeGuids I get a message saying "The project file projectname.csproj cannot be opened. The project type is not supported by this installation."
I do have MVC3 installed and am running VS2010, so I don't know what could the going wrong. Anyone have any thoughts on the matter? Thanks!
EDIT:
For what it's worth. If I create a blank project from scratch, I have the ability to create a new MVC3 project. However, if I right click on my solution and click add->New Project... I can only add MVC2 projects. This leads me to think that the solution is configured somehow to only support MVC2, however I can't figure out how to change it.
There is an extra package which is ASP.NET MVC 3 Tools Update, you must download and install it too.
Solution 1:
Open the visual Studio Find In Files Dialog and Select your project folder, then search for old GUID and replace it with new one exactly. Backup the directory before doing this.
Actually You must select the whole solution folder and search all the files not a specific extension.
Solution 2:
You must take a careful look at your csproj and sln files and compare it with a working one on your system to find the difference. if you have file compare tools like winmerge, use it to compare files character by character

Where should I place resources.resx in a ASP.NET web application?

I'm a newbie with ASP.NET web applications. When I create an ASP.NET web app project, there's a file called resources.resx in the folder My Project. Working in my computer I can access this file and its content without any problem. But when I deploy the application I can't access this file. I've tried copying the file seperately, and the folder (My Project) seperately, with the file in it, but no luck. Is there a way to achieve this?
PS: I've read something about implicit localization and explicit localization but I'd like to know if it can be done this way.
It's embedded into your DLL when you build (compile). So you can't change it when it's deployed.
If you want to see it in your DLL, you'll have to use a tool like Reflector, dotPeek, etc.
You can read more on resources here, starting from the 'Compiling Resources into Assemblies' title (as you know how to use them by now).
Well my suggestion is to use global and local resources.
In production you'll have resx file stored in:
App_GlobalResources: available in all application
App_LocalResources: one for each folder you want resources.
They are XML files visibile and editable.
I use it to allow me to modify string localization resources without recompiling and deploying.
And you can also give a web interface to the end user to allow him to self translate and localize strings at runtime.

MvcBuildViews seems to build more files than are included in the .csproj file

Is there any way to limit the view building to only files included in the .csproj file? Or is there at least a way to exclude certain folders from being built?
In our project folder structure we have an \Admin\Mocks folder which contains lots of mocked up .aspx and .cshtml files, and while the \Admin\Mocks folder isn't included in the .csproj file (though \Admin is), it seems that all the files in that tree are getting built. This of course generates LOTS of build errors.
I'm not sure that this makes a difference, but our project is a hybrid WebForms/Mvc3 application (both WebForms and Razor View Engines) using Asp.Net 4.
Based on the time stamp I assume you eventually worked around this but I got here Googling for a solution to the same problem.
We have a bunch of old Webforms views that are only checked in (not referenced by the project) for reference purposes and for A/B testing while we are updating the application. (Webforms -> Razor, MVC2 -> MVC4, etc)
This was an issue as both the .cshtml and .aspx files were being built and the errors from the Webform views were breaking the build.
The solution for us was to rename the the old view files from Index.aspx to Index.aspx.old
(In your case I would suggest Index.aspx.mock ?)
This meant they were excluded from the MvcBuildViews = True processing, but were still easily accessible and able to be opened from Visual Studio.
The additional benefit is you can change the default open with for that extension to use the Webforms editor so you still get highlighting and all.
If possible, create a separate web project and put the content you don't want to be built in there, making sure to set MVCBuildViews to false.

recover project in visual studio 2010

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.

Resources