简体   繁体   中英

How to start the Azure emulator with an ASP.NET MVC project

I have an ASP.NET MVC project that uses Azure Storage and has been successfully deployed to Azure. However when run the project locally, it does not start the Azure emulator.

The only way I have found of starting the Azure emulator is to make a 'Windows Azure Cloud Service' shortcut and run that manually.

Is there a way to make ensure the Azure emulator runs when I start my app?

I have a cloud service in the same project as my MVC site. Since you've already created the MVC project give this a try...

  1. Add new Cloud project to your solution. DONT SELECT ANY ROLES WHEN ADDING.
  2. Once the Cloud project is add, right click the Roles and slect...
    • Add "Web Role Project in solution..." There you will be able to select you MVC project.
  3. Last but not least, set the Cloud project as the start up project and it will start the appropriate compute and storage emulators when running locally.

I Just verified this in VS2012, it had been a couple of months since I had done it.

Without a cloud services project inside your solution, it might be tricky. There're a few things you could do:

  1. Start storage emulator when the computer starts.
  2. Look at how VS does it when you start a project with cloud service.
  3. Start storage emulator in your code when you start debugging your application. What you could do is start the storage emulator process in your Application_Start() method using code something like this [It's obviously a hack, and not sure an elegant one :)]:

      protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); #if (DEBUG) { Process.Start(@"C:\\Program Files\\Microsoft SDKs\\Windows Azure\\Emulator\\devstore\\DSServiceLDB.exe"); } #endif } 

My guess is that with this you would need to run VS as Administrator. I tried the above code, and it worked fine. The code above assumes that your storage emulator uses LocalDB for storage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM