Nota
O acesso a esta página requer autorização. Pode tentar iniciar sessão ou alterar os diretórios.
O acesso a esta página requer autorização. Pode tentar alterar os diretórios.
The Service Fabric Reliable Services extension for VS Code makes it easy to build .NET Core Service Fabric applications on Windows, Linux, and macOS operating systems.
This article shows you how to build, deploy, and debug a .NET Core Service Fabric application using Visual Studio Code.
Pré-requisitos
Este artigo pressupõe que você já tenha instalado o VS Code, a extensão de Serviços Confiáveis do Service Fabric para VS Code e quaisquer dependências necessárias para seu ambiente de desenvolvimento. Para saber mais, consulte Introdução.
Transferir o exemplo
This article uses the CounterService application in the Service Fabric .NET Core getting started samples GitHub repository.
Para clonar o repositório para sua máquina de desenvolvimento, execute o seguinte comando em uma janela do terminal (janela de comando no Windows):
git clone https://github.com/Azure-Samples/service-fabric-dotnet-core-getting-started.git
Abra o aplicativo no VS Code
Windows
Right-click the VS Code icon in the Start Menu and choose Run as administrator. To attach the debugger to your services, you need to run VS Code as administrator.
Linux
Using the terminal, navigate to the path /service-fabric-dotnet-core-getting-started/Services/CounterService from the directory that the application was cloned into locally.
Run the following command to open VS Code as a root user so that the debugger can attach to your services.
sudo code . --user-data-dir='.'
The application should now appear in your VS Code workspace.
Criar o aplicativo
Pressione (Ctrl + Shift + p) para abrir a Paleta de comandos no VS Code.
Procure e selecione o comando Service Fabric: Build Application . The build output is sent to the integrated terminal.
Implantar o aplicativo no cluster local
Depois de criar o aplicativo, você pode implantá-lo no cluster local.
Na Paleta de comandos, selecione o comando Service Fabric: Deploy Application (Localhost). A saída do processo de instalação é enviada para o terminal integrado.
When the deployment is complete, launch a browser and open Service Fabric Explorer: http://localhost:19080/Explorer. Você deve ver que o aplicativo está em execução. Isto pode levar algum tempo, por isso seja paciente.
After you've verified the application is running, launch a browser and open this page: http://localhost:31002. Este é o front-end web do aplicativo. Refresh the page to see the current value of the counter as it increments.
Publish the application to an Azure Service Fabric cluster
Along with deploying the application to the local cluster, you can also publish the application to a remote Azure Service Fabric cluster.
Ensure that you have built your application using the instructions above. Update the generated configuration file
Cloud.json
with the details of the remote cluster you want to publish to.From the Command Palette, select the Service Fabric: Publish Application command. A saída do processo de instalação é enviada para o terminal integrado.
Quando a implantação estiver concluída, inicie um navegador e abra o Service Fabric Explorer:
https:<clusterurl>:19080/Explorer
. Você deve ver que o aplicativo está em execução. Isto pode levar algum tempo, por isso seja paciente.
Depurar o aplicativo
Ao depurar aplicações no VS Code, a aplicação deve estar a ser executada num cluster local. Os pontos de interrupção podem então ser adicionados ao código.
To set a breakpoint and debug, complete the following steps:
In Explorer, open the /src/CounterServiceApplication/CounterService/CounterService.cs file and set a breakpoint at line 62 inside the
RunAsync
method.Clique no ícone Depurar na barra de atividades para abrir a visualização do depurador no VS Code. Click the gear icon at the top of the debugger view and select .NET Core from the dropdown environment menu. The launch.json file opens. You can close this file. Now you should see configuration choices in the debug configuration menu located next to the run button (green arrow).
Select .NET Core Attach from the debug configuration menu.
Open Service Fabric Explorer in a browser: http://localhost:19080/Explorer. Click Applications and drill down to determine the primary node that the CounterService is running on. In the image below the primary node for the CounterService is Node 0.
In VS Code, click the run icon (green arrow) beside the .NET Core Attach debug configuration. In the process selection dialog, select the CounterService process that is running on the primary node that you identified in step 4.
The breakpoint in the CounterService.cs file will be hit very quickly. You can then explore the values of the local variables. Use the Debug toolbar at the top of VS Code to continue execution, step over lines, step into methods, or step out of the current method.
To end the debugging session, click the plug icon on the Debug toolbar at the top of VS Code..
When you've finished debugging, you can use the Service Fabric: Remove Application command to remove the CounterService application from your local cluster.