ASP.NET 5 Web应用程序作为Azure Web角色?

时间:2022-10-15 03:31:13

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

我们的解决方案中有一个ASP.NET 5 Web应用程序。

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

通常,我们可以右键单击Cloud Service“角色”项,并从解决方案中的现有项目添加新角色。

But it cannot identity this project as a Web Role:

但它不能将此项目标识为Web角色:

ASP.NET 5 Web应用程序作为Azure Web角色?

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

我们如何在Azure Web角色中托管ASP.NET 5项目?

Edit: We are using Azure SDK 2.7

编辑:我们正在使用Azure SDK 2.7

5 个解决方案

#1


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.

对不起,我们目前不支持WebRoles。你可能*能够破解你的方式,但正式没有支持。这意味着你所做的任何黑客都将在文本编辑器中,而不是工具。

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

但是,您可以使用Azure WebSite。这完全得到了支持。

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

*它可能根本不起作用。我不知道有谁这样做过。

#2


3  

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

您可能必须使用CSPack自己构建程序包。这是一个使用PowerShell和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.

它还允许您在单个Web角色上托管多个站点。

#3


1  

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

编辑:无法使用Azure存储模拟器完成...

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.

我真的很挣扎,因为我发现文档很糟糕,没有适当的例子,所以这里有一个完整的例子,我的脚本和文件供其他人使用,基于Martin Brandl的回答。您不需要webRoleEntryPoint仅用于Web角色。仅用于工作者角色。

  • 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.

    在项目中创建一个新的空云服务。这将为您生成emptyServiceConfigiguration.Cloud.csfg,ServiceConfigiguration.Cloud.csfg和ServiceDefinition.csdef文件以及空角色文件夹。您还可以添加Web /辅助角色,让visual studio在其中生成配置,然后相应地修改它们。

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

    修改这些文件(将physicalDirectory更改为您自己的文件):

ServiceDefinition.csdef:

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.

是重要的一行,这个physicalDirectory是相对于你的.csdef文件所在的位置而我想让我的主项目SoundVast成为一个位于一个级别的web角色向上。

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

ServiceConfiguration.Cloud.csfg和ServiceConfiguration.Local.csfg(两者都可以相同):

<?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.

重要的是角色名称与您的 服务定义文件Web角色名称相匹配。

# 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.

现在应该在$ PackagePath的位置生成.cspkg文件。

#4


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

它似乎目前尚未正式支持作为Web角色。它似乎只与Web应用程序兼容,而不是旧的Web角色。目前的工作原理记录在本网站上:http://www.codeproject.com/Articles/331425/Running-an-EXE-in-a-WebRole-on-Windows-Azure

#5


0  

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/

我刚刚在博客上写了如何做到这一点(使用VS工具支持!):https://oren.codes/2017/10/16/using-asp-net-core-with-azure-cloud-services/

#1


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.

对不起,我们目前不支持WebRoles。你可能*能够破解你的方式,但正式没有支持。这意味着你所做的任何黑客都将在文本编辑器中,而不是工具。

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

但是,您可以使用Azure WebSite。这完全得到了支持。

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

*它可能根本不起作用。我不知道有谁这样做过。

#2


3  

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

您可能必须使用CSPack自己构建程序包。这是一个使用PowerShell和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.

它还允许您在单个Web角色上托管多个站点。

#3


1  

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

编辑:无法使用Azure存储模拟器完成...

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.

我真的很挣扎,因为我发现文档很糟糕,没有适当的例子,所以这里有一个完整的例子,我的脚本和文件供其他人使用,基于Martin Brandl的回答。您不需要webRoleEntryPoint仅用于Web角色。仅用于工作者角色。

  • 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.

    在项目中创建一个新的空云服务。这将为您生成emptyServiceConfigiguration.Cloud.csfg,ServiceConfigiguration.Cloud.csfg和ServiceDefinition.csdef文件以及空角色文件夹。您还可以添加Web /辅助角色,让visual studio在其中生成配置,然后相应地修改它们。

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

    修改这些文件(将physicalDirectory更改为您自己的文件):

ServiceDefinition.csdef:

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.

是重要的一行,这个physicalDirectory是相对于你的.csdef文件所在的位置而我想让我的主项目SoundVast成为一个位于一个级别的web角色向上。

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

ServiceConfiguration.Cloud.csfg和ServiceConfiguration.Local.csfg(两者都可以相同):

<?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.

重要的是角色名称与您的 服务定义文件Web角色名称相匹配。

# 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.

现在应该在$ PackagePath的位置生成.cspkg文件。

#4


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

它似乎目前尚未正式支持作为Web角色。它似乎只与Web应用程序兼容,而不是旧的Web角色。目前的工作原理记录在本网站上:http://www.codeproject.com/Articles/331425/Running-an-EXE-in-a-WebRole-on-Windows-Azure

#5


0  

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/

我刚刚在博客上写了如何做到这一点(使用VS工具支持!):https://oren.codes/2017/10/16/using-asp-net-core-with-azure-cloud-services/