Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

July 25, 2014

I generated two scripts using Database project in Visual studio - one for updating the database and another for rollback if deployment fails. When I ran the update script, the database updated fine but I ran the rollback script - it failed with the message "Rows were detected. The schema update is terminating because data loss might occur". The issue is somewhat obvious; I have added new fields in a table and if I rollback, meaning if drop those fields then any data in those fields will be lost. So, how can we create script so we can run it. Since the script is needed for rollback, it might be necessary to run it.

June 5, 2014

I cloned a project from source control repository and then opened it Visual Studio and straight way got a message that I cannot switch branches because of ResolveAssemblyReference.cache . So, what exactly is  ResolveAssemblyReference.cache?

I did searches in internet and most answers were not to worry about it. MSDN claims that this and other files like - ResolveAssemblyReferences, ResolveCOMReferences, GetFrameworkPaths, and CopyRunEnvironmentFiles - are needed for the design time in Visual Studio to work properly and intellisense may fail, however, there is no issues in building the project if these files are missing.

After thinking about it, I figured that the initial project is created using Visual Studio 2013 whereas I was loading the project in Visual Studio 2012 which is why the file generated was different from the one downloaded.

May 5, 2014

Browser Link in Visual Studio 2013

Browser Link is a new feature in Visual Studio 2013 and it allows refreshing of multiple browsers at once. This is great for web developers as now we can test the application in multiple browsers and make modifications and see the changes all at once.

December 10, 2013

I use Visual Studio 2012 and I have noticed that every now and then the UI crashes. More often than not the issues happen with the Dark theme - sometimes the UI will look strange and not workable with. Other times the UI is workable but it would look funny - like highlighting would not work properly or the line numbers will have the white theme when the UI will have the dark theme. Some of the screen shots for this behaviour is below.

November 1, 2012

In Asp.Net Mvc, Controllers are classes that query or update model data, load a specific View template and handle user inputs. Controllers can be added in an Mvc project by right clicking the Controllers directory and choosing Add > Controller.

1

I have named the Controller - DemoController - note the naming convention.

2

Visual Studio generates the following code by default.

Default Controller Code
  1. namespace MvcDemo.Controllers
  2. {
  3.     public class DemoController : Controller
  4.     {
  5.         //
  6.         // GET: /Demo/
  7.  
  8.         public ActionResult Index()
  9.         {
  10.             return View();
  11.         }
  12.  
  13.     }
  14. }

I will update the Index() method to return some string.

Index Method
  1. public string Index()
  2. {
  3.     return "You are viewing Index method od DemoController";
  4. }

Note that, I have changed the return type from ActionResult to string. Then, run the page in debug mode and the url http://localhost:50376/demo produce the result shown below. As you can see, its the same string that was part of the Index method.

3

The important thing to note is the url ends with /demo which is also the Controller’s name. In Mvc, the url controls the Controller, Method and parameters passed to the application. It has the format /Controller/Method/{Parameters} . Index is the default method name and therefore not needed to be specified.

I will now add another method - Home – that will display the name and age based on parameters.

Home Method
  1. public string Home(string name, int age)
  2. {
  3.     return "Hello " + name + ". You are " + age.ToString() + " years old";
  4. }

It’s a simple method that return a string based on the parameters. When the page is run, the following is displayed.

4

Note that, MVC automatically binds the query strings to the relevant parameters in the method.

October 31, 2012

In this post, I will show how to create an asp.net MVC 4.0 project using Visual Studio 10 SP1. The built in templates in Visual Studio makes it easy to start creating the application. In the screenshot below, I have opened Visual Studio, and creating a new MVC 4.0 project using .NET 4.0 . I have called the solution MvcDemo.

1

After clicking OK, I will choose Internet Application as the template and Razor as the view engine and also create unit test project.

2

Visual Studio creates a working application once the OK button is hit. Folders and files have been created by default for Controllers, Models, Views, Filters, Scripts, Contents, etc. The screen shot below shows the full structure.

3

The application can now be started in Debug mode by hitting F5.

4

The application, by default, shows some informative messages. It’s important to note that the data for this page is obtained from Index.cshtml View which is under the Home sub-folder of View folder. The View contains mostly static content and dynamically obtains some information referred ViewBag.Message and ViewBag.Title property as shown below.

5

The value of ViewBag.Title property is set in the first couple of lines within the View. The ViewBag.Message property is set within the Index() method of HomeController class which is located within the Controller directory.

HomeController
  1. namespace MvcDemo.Controllers
  2. {
  3.     public class HomeController : Controller
  4.     {
  5.         public ActionResult Index()
  6.         {
  7.             ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
  8.  
  9.             return View();
  10.         }
Reference: Shahed Kazi at AspNetify.com