抱歉,我们目前不支持WebRoles。你可能能够用一些方法绕过去,但是官方上并没有提供支持。这也就意味着,任何你所做的修改都需要通过文本编辑器实现,而非工具。
不过,你可以尝试使用Azure WebSite替代,因为这是完全受支持的。
* 但这并不保证一定能够正常运行,我也没有听说过有人这样做成功了。
您可能需要使用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
$webRoleEntryPoint
,我一直收到错误提示CloudServices077:需要为角色webrole1的虚拟路径Web/指定物理目录
。我将其指向包含ServiceDefinition.csdef
的Azure云目录。 - Martin DawsonphysicalDirectory="../SoundVast"
。 $webRoleEntryPoint
可以省略,它只适用于工作角色。 - Martin Dawson编辑:无法使用Azure存储模拟器完成...
我在这方面遇到了很大的困难,因为我发现文档非常贫乏,没有适当的示例,所以这里提供一个完整的脚本和文件示例,供其他人参考,基于Martin Brandl的答案。
对于仅有Web角色的情况,您不需要webRoleEntryPoint
。只用于工作角色。
在您的项目中创建一个新的空云服务。这将为您生成空的ServiceConfigiguration.Cloud.csfg
、ServiceConfigiguration.Cloud.csfg
和ServiceDefinition.csdef
文件,以及一个空的roles文件夹。您也可以添加一个Web/Worker角色,让Visual Studio为它们生成配置,然后进行相应的修改。
修改这些文件(将physicalDirectory
更改为您自己的目录):
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">
是重要的一行,这里的 physicalDirectory
是相对于你的 .csdef
文件所在位置的路径,我想把我的主项目 SoundVast
设置为 Web 角色,而该角色位于上一级。
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>
<Role name="WebRole1">
服务定义文件的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
现在,一个.cspkg
文件应该已经生成在您的$PackagePath
所在位置。
我刚刚在这里写了一篇博客,介绍了如何做到这一点(并获得了VS工具支持!):https://oren.codes/2017/10/16/using-asp-net-core-with-azure-cloud-services/
目前看来,它并没有作为 Web 角色得到官方支持。似乎它只与 Web 应用程序兼容而不是旧的 Web 角色。当前的解决方法在此网站上有记录: http://www.codeproject.com/Articles/331425/Running-an-EXE-in-a-WebRole-on-Windows-Azure