12

We have a ASP.NET 5 web application in our solution.

Typically, we could right click on the Cloud Service "Roles" item and add a new role from an existing project in the solution.

But it cannot identity this project as a Web Role:

Add Web Role Project in solution...

How are we able to host a ASP.NET 5 project in a Azure Web Role?

Edit: We are using Azure SDK 2.7

Dave New
  • 38,496
  • 59
  • 215
  • 394

5 Answers5

3

You probably have to build your package yourself using CSPack. Here an example using PowerShell and CSPack:

# path to cspack
$cspackPath = Join-Path $env:ProgramFiles 'Microsoft SDKs\Azure\.NET SDK\v2.7\bin\cspack.exe'

$PackagePath = 'c:\mycloudpackage.cspkg'
$serviceDefinitionFile = 'c:\myProject\ServiceDefinition.csdef'
$webRoleName = 'MyWebRole'
$webRolePath = 'c:\myProject'
$webRoleEntryPoint = 'MyWebRole.dll'

# define the cspack parameters
$cspackParameter = @(
        "/out:$PackagePath",
        $serviceDefinitionFile,
        "/role:$webRoleName;$webRolePath;$webRoleEntryPoint",
        "/sites:$webRoleName;Web;$webRolePath"
    )

# execute cspack
& $cspackExe @cspackParameter

It also allows you to host multiple sites on a single web role.

Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
  • The link you provided doesn't point to anything in particular. Could you please provide a bit more information or update the link? – Martin Dawson Jul 25 '16 at 10:02
  • 1
    I think the script doesn't need more explanation. However, I updated the link. – Martin Brandl Jul 25 '16 at 10:08
  • I'm following this script without the `$webRoleEntryPoint` and I keep getting the error `CloudServices077: Need to specify the pshyical directory for the virtual path Web/ of role webrole1`. I am pointing it to the azure cloud directory that holds `ServiceDefinition.csdef`. – Martin Dawson Jul 25 '16 at 14:42
  • 1
    I firgured it out, I was missing: `physicalDirectory="../SoundVast"` in .csdef file. `$webRoleEntryPoint` can be left out, it's only required for worker roles. – Martin Dawson Jul 26 '16 at 19:11
3

Sorry, we don't support WebRoles at the moment. You might* be able to hack your way around but officially there is no support. That means that any hack you do, will be in a text editor, not from tooling.

However, you can use an Azure WebSite instead. That's fully supported.

* it might not work at all. I am not aware of anyone who did this.

Victor Hurdugaci
  • 28,177
  • 5
  • 87
  • 103
  • Would love to know if anyone does get this working. I gave it a half hour and decided to sanity check here with SO. Given that even for .NET 4.6 and guest OS family 4 you have to manually install netfx 4.6, I think it'll take some future work to get there. – Jeff Wilcox Aug 19 '15 at 20:46
  • Are there plans to support this in the future? – Ender2050 Oct 08 '15 at 14:46
  • I cannot use a WebSite (now WebApp) right now as I have some legacy COM objects I need to register for some older code and I can only do this with a Cloud Service ... but I want to use the latest asp.net rather than re-code it again later on ... as Ender asked, will WebRoles ever be supported? – Dan Nov 04 '15 at 16:00
  • This is really frustrating. We can't use Web Apps because they can only be internet facing (except via web.config whitelisting - not good enough). And we can't use Web Roles because they don't support Asp.Net 5. So either we ditch Azure or ditch Asp.Net 5. – Ian1971 Feb 09 '16 at 16:20
  • This is terrible. Can't use asp.net core with azure storage emulator. Hacking around with CSpack, CSrun doesn't work. When will asp.net core be supported for web roles? – Martin Dawson Jul 31 '16 at 09:01
1

Edit: Cannot be done with Azure Storage Emulator...

I really struggled with this as I found the documentation seriously poor with no proper examples, so here's a full example of my scripts and files for anyone else, based on Martin Brandl's answer. You do not need webRoleEntryPoint for only a web role. Only used for worker roles.

  • Create a new empty cloud service in your project. This will generate emptyServiceConfigiguration.Cloud.csfg, ServiceConfigiguration.Cloud.csfg and ServiceDefinition.csdef files for you as well as an empty roles folder. You could also add a web/worker role to let visual studio generate the configuration in them and then just modify them accordingly.

  • Modify these files (change the physicalDirectory to your own):

ServiceDefinition.csdef:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="SoundVast.Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2015-04.2.6">
  <WebRole name="WebRole1" vmsize="Small">
    <Sites>
      <Site name="Web" physicalDirectory="../SoundVast">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
        </Bindings>
      </Site>
    </Sites>
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />
    </ConfigurationSettings>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
    </Endpoints>
  </WebRole>
</ServiceDefinition>

<Site name="Web" physicalDirectory="../SoundVast"> is the important line, this physicalDirectory is relative to wherever your .csdef file is located and I wanted to make my main project SoundVast the web role which was located one level up.

ServiceConfiguration.Cloud.csfg and ServiceConfiguration.Local.csfg (both can be the same):

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="SoundVast.Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">
  <Role name="WebRole1">
    <Instances count="1" />
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
    </ConfigurationSettings>
  </Role>
</ServiceConfiguration>

The important part is that the role name matches your <Role name="WebRole1"> service definition files web role name.

# path to cspack
$cspackPath = Join-Path $env:ProgramFiles 'Microsoft SDKs\Azure\.NET SDK\v2.8\bin\cspack.exe'

$PackagePath = 'C:\Users\Yamo\Documents\visual studio 2015\Projects\SoundVast\SoundVast.Azure\SoundVast.cspkg'
$serviceDefinitionFile = 'C:\Users\Yamo\Documents\visual studio 2015\Projects\SoundVast\SoundVast.Azure\ServiceDefinition.csdef'
$webRoleName = 'WebRole1'
$webRolePath = 'C:\Users\Yamo\Documents\visual studio 2015\Projects\SoundVast\SoundVast.Azure'

# define the cspack parameters
$cspackParameter = @(
        $serviceDefinitionFile,
        "/role:$webRoleName;$webRolePath;",
        "/sites:$webRoleName;SoundVast;$webRolePath",
        "/out:$PackagePath"
    )

# execute cspack
& $cspackPath @cspackParameter

A .cspkg file should now have been generated at the location of your $PackagePath.

Martin Dawson
  • 7,455
  • 6
  • 49
  • 92
1

I've just blogged on how to do this (with VS tooling support!) here: https://oren.codes/2017/10/16/using-asp-net-core-with-azure-cloud-services/

Claire Novotny
  • 1,593
  • 1
  • 15
  • 19
0

It appears that it isn't officially supported as a web role at this time. It seems that it is only compatible with the web apps and not the older web role. The current work around is documented on this site: http://www.codeproject.com/Articles/331425/Running-an-EXE-in-a-WebRole-on-Windows-Azure

Jonathan
  • 1,725
  • 3
  • 19
  • 45