ASP.NET 5 web application as Azure Web Role?

后端 未结 5 1565
我寻月下人不归
我寻月下人不归 2021-02-19 18:15

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 t

5条回答
  •  無奈伤痛
    2021-02-19 18:28

    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:

    
    
      
        
          
            
              
            
          
        
        
          
        
        
          
        
      
    
    

    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):

    
    
      
        
        
          
        
      
    
    

    The important part is that the role name matches your 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.

提交回复
热议问题