如何使用二头肌部署Windows Azure应用服务与.Net堆栈?

z18hc3ub  于 2023-01-05  发布在  Windows
关注(0)|答案(2)|浏览(129)

我已经创建了一个Bicep,以使用linux/windows选择和.net 6堆栈部署服务计划和应用程序服务。两个部署都成功,Linux应用程序完全正常,.net 6堆栈出现在门户网站上。但是,Windows stack在门户网站屏幕上为空。
我使用以下参数:
二头肌linux参数:

linuxFxVersion: 'DOTNETCORE|6.0'

二头肌窗口参数:

windowsFxVersion: 'dotnet:6'
  netFrameworkVersion: 'v6.0'

用这个命令我可以得到允许的windows堆栈,所以dotnet:6应该可以

[ ~ ]$ az webapp list-runtimes --os windows --os-type windows
[
  "dotnet:7",
  "dotnet:6",
  "ASPNET:V4.8",
  "ASPNET:V3.5",
  "NODE:18LTS",
...

我可以用Powershell看到,我的设置应用到了Web App
我试过不同的选择比如dotnet| 6、网络核心|6或没有netFrameworkVersion,并没有找到正确的设置。是Azure接口错误还是我错过了什么?提前感谢,下面附上整个二头肌。

@description('Generate unique String for resource names')
param uniqueFullRGString string = uniqueString(resourceGroup().id)

@description('Short unique name based on RG name')
param uniqueRGString string = take(uniqueFullRGString, 4)

@description('Resource group location')
param location string = resourceGroup().location

@description('Azure Tenant Id')
var azureTenantId = tenant().tenantId

@description('App Service Plan OS')
@allowed([
  'linux'
  'windows'
])
param appServicePlanOS string

var linuxOffer = 'linux'
var windowsOffer = 'windows'

@description('App Service Plan SKU')
param appServicePlanSku string = 'F0'

var configReferenceLinux = {
  linuxFxVersion: 'DOTNETCORE|6.0'
  appSettings: [
    {
      name: 'TenantId'
      value: azureTenantId
    }
  ]
}

var configReferenceWindows = {
  windowsFxVersion: 'dotnet:6'
  netFrameworkVersion: 'v6.0'
  appSettings: [
    {
      name: 'TenantId'
      value: azureTenantId
    }
  ]
}

@description('App Service Plan name')
var appServicePlanName = 'App-${uniqueRGString}'

resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appServicePlanName
  location: location
  sku: {
    name: appServicePlanSku
  }
  properties: {
      reserved: ((appServicePlanOS == 'linux') ? true : false)
  }
  kind: ((appServicePlanOS == 'linux') ? linuxOffer : windowsOffer)
}

resource appService 'Microsoft.Web/sites@2020-06-01' = {
  name: appServicePlanName
  location: location
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig: ((appServicePlanOS == 'linux') ? configReferenceLinux : configReferenceWindows)
  }
  identity: {
    type: 'SystemAssigned'
  }
}
4c8rllxm

4c8rllxm1#

如果您尝试在Windows应用服务计划上部署.NET堆栈Web应用,则需要添加元数据块,该块用于定义此sample ARM template中提到的Web应用的运行时,以便在Windows应用服务计划上创建.NET应用。
我已经修改了上面共享的bicep示例,并测试了它是否能够使用运行在.NET堆栈上的webapp部署windows应用程序服务计划。

@description('Generate unique String for resource names')
param uniqueFullRGString string = uniqueString(resourceGroup().id)

@description('Short unique name based on RG name')
param uniqueRGString string = take(uniqueFullRGString, 4)

@description('Resource group location')
param location string = resourceGroup().location

@description('Azure Tenant Id')
var azureTenantId = tenant().tenantId

@description('App Service Plan OS')
@allowed([
  'linux'
  'windows'
])
param appServicePlanOS string

var linuxOffer = 'linux'
var windowsOffer = 'windows'

@description('App Service Plan SKU')
param appServicePlanSku string = 'F0'

var configReferenceLinux = {
  linuxFxVersion: 'DOTNETCORE|6.0'
  appSettings: [
    {
      name: 'TenantId'
      value: azureTenantId
    }
  ]
}

var configReferenceWindows = {
  metadata :[
    {
      name:'CURRENT_STACK'
      value:'dotnet'
    }
  ]
  netFrameworkVersion:'v7.0'
  appSettings: [
    {
      name: 'TenantId'
      value: azureTenantId
    }
  ]
}

@description('App Service Plan name')
var appServicePlanName = 'App-${uniqueRGString}'

resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
  name: appServicePlanName
  location: location
  sku: {
    name: appServicePlanSku
  }
  properties: {
      reserved: ((appServicePlanOS == 'linux') ? true : false)
  }
  kind: ((appServicePlanOS == 'linux') ? linuxOffer : windowsOffer)
}

resource appService 'Microsoft.Web/sites@2020-06-01' = {
  name: appServicePlanName
  location: location
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig: ((appServicePlanOS == 'linux') ? configReferenceLinux : configReferenceWindows)
  }
  identity: {
    type: 'SystemAssigned'
  }
}

供参考的输出屏幕截图示例:

您也可以参考类似的SO thread

dzhpxtsq

dzhpxtsq2#

我在我的环境中运行了您的代码,得到了相同的结果(空运行时堆栈)。然后我将提供程序***“Microsoft. Web/sites”版本更改为“2021-03-01”***,它成功运行,因为很少有部署版本会引发此类错误。

  • 我对您的代码做了一些更改,并找到以下代码片段。*
resource  appService  'Microsoft.Web/sites@2021-03-01' = {
name: appServicePlanName 
location: "EastUS" //location
properties: {
serverFarmId: appServicePlan.id
siteConfig: ((appServicePlanOS  ==  'windows') ?  configReferenceLinux  :  configReferenceWindows)
}
identity: {
type: 'SystemAssigned'
}
}

部署成功:

App service -> configuration -> General settings -> Stack settings设置为给定的运行时堆栈&版本:

相关问题