ã¯ããã«
ãã®ãã¥ãŒããªã¢ã« ã¬ã€ãã§ã¯ãC# (.NET) ãããžã§ã¯ãã®äŸã®èšå®æ¹æ³ã玹ä»ããŸã Visual Studio Code Web ã¯ã©ã€ã¢ã³ãã䜿çšãã GitHub Codespaces ã§ã codespace ã§ãããžã§ã¯ããéããäºåå®çŸ©æžã¿ã®éçºã³ã³ãããŒã®æ§æã远å ããã³å€æŽããããã»ã¹ã«ã€ããŠèª¬æããŸãã
ãã®ãã¥ãŒããªã¢ã«ãå®äºãããšãVS Code Web ã¯ã©ã€ã¢ã³ããŸã㯠VS Code ãã¹ã¯ããã ã¢ããªã±ãŒã·ã§ã³ã䜿çšããŠãç¬èªã®ãªããžããªã«éçºã³ã³ãããŒæ§æã远å ã§ããããã«ãªããŸãã
éçºã³ã³ãããŒã®è©³çްã«ã€ããŠã¯ããéçºã³ã³ãããŒã®æŠèŠããåç §ããŠãã ããã
ã¹ããã 1: codespace ã§ãããžã§ã¯ããéã
-
ãŸã ãµã€ã³ã€ã³ããŠããªãå Žåã¯ãGitHub.com ã«ãµã€ã³ã€ã³ããŸãã
-
https://github.com/microsoft/vscode-remote-try-dotnet ã«ã¢ã¯ã»ã¹ããŸãã
-
[ãã®ãã³ãã¬ãŒãã䜿çšãã] ãã¯ãªãã¯ãã [codespace ã§éã] ãéžã³ãŸãã
codespace ãäœæãããšããããžã§ã¯ããå°çšã®ãªã¢ãŒãä»®æ³ãã·ã³äžã«äœæãããŸãã æ¢å®ã§ã¯ãcodespace ã®ã³ã³ãããŒã«ã¯ã.NET ãå«ãå€ãã®èšèªãšã©ã³ã¿ã€ã ããããŸãã ãŸããgitãwgetãrsyncãopensshãnano ãªã©ã®äžè¬çãªããŒã«ã»ãããå«ãŸããŠããŸãã
codespace ãã«ã¹ã¿ãã€ãºããã«ã¯ãvCPU ãš RAM ã®éã調æŽããããdotfile ã远å ããŠç°å¢ãã«ã¹ã¿ãã€ãºããããã€ã³ã¹ããŒã«ãããŠããããŒã«ãã¹ã¯ãªããã倿ŽããŸãã 詳ããã¯ããcodespace ã®ã«ã¹ã¿ãã€ãºããã芧ãã ããã
GitHub Codespaces ã¯ãdevcontainer.json
ãšãããã¡ã€ã«ã䜿ã£ãŠãcodespace ã§äœæ¥ãããšãã«äœ¿ãéçºã³ã³ãããŒãæ§æããŸãã åãªããžããªã«ã¯ 1 ã€ä»¥äžã® devcontainer.json
ãã¡ã€ã«ãå«ããããšãã§ããcodespace ã§ã³ãŒããæäœããããã«å¿
èŠãªéçºç°å¢ãæ£ç¢ºã«æäŸã§ããŸãã
èµ·åæã«ãGitHub Codespaces 㯠devcontainer.json
ãã¡ã€ã«ãšãéçºã³ã³ãããŒã®æ§æãèšå®ããäŸåãã¡ã€ã«ã䜿ã£ãŠãããŒã«ãã©ã³ã¿ã€ã ãã€ã³ã¹ããŒã«ãããããžã§ã¯ããå¿
èŠãšãããã®ä»ã®ã»ããã¢ãã ã¿ã¹ã¯ãå®è¡ããŸãã 詳ããã¯ããéçºã³ã³ãããŒã®æŠèŠããã芧ãã ããã
ã¹ããã 2: éçºã³ã³ãããŒæ§æã远å ãã
GitHub Codespaces ã®æ¢å®ã®éçºã³ã³ãã㌠("éçºã³ã³ãããŒ") ã«ã¯ã.NET ã®ææ°ããŒãžã§ã³ãšäžè¬çãªããŒã«ããã¬ã€ã³ã¹ããŒã«ãããŠããŸãã ãã ããç¬èªã®éçºã³ã³ãããŒãæ§æããŠããããžã§ã¯ãã«å¿ èŠãªãã¹ãŠã®ããŒã«ãšã¹ã¯ãªãããå«ããããšããå§ãããŸãã ããã«ããããªããžããªã®ãã¹ãŠã® GitHub Codespaces ãŠãŒã¶ãŒã«å¯ŸããŠãå®å šã«åçŸå¯èœãªç°å¢ãä¿èšŒãããŸãã
ã«ã¹ã¿ã éçºã³ã³ãããŒã䜿çšããããã«ãªããžããªãèšå®ããã«ã¯ãdevcontainer.json
ãã¡ã€ã«ã 1 ã€ä»¥äžäœæããå¿
èŠããããŸãã ããã¯ãå®çŸ©æžã¿ã®æ§æãã³ãã¬ãŒããã远å ããããVisual Studio Code å
ã«è¿œå ãããããŸãã¯ç¬èªã«èšè¿°ããããšãã§ããŸãã éçºã³ã³ãããŒã®æ§æã®è©³çްã«ã€ããŠã¯ããéçºã³ã³ãããŒã®æŠèŠããåç
§ããŠãã ããã
-
Visual Studio Code Command Palette ã«ã¢ã¯ã»ã¹ (Shift + Command + P / Ctrl + Shift + P) ãããéçºã®è¿œå ããšå ¥åããŸãã [Codespaces: éçºã³ã³ãããŒæ§æãã¡ã€ã«ã®è¿œå ] ãã¯ãªãã¯ããŸãã
-
[æ°ããæ§æã®äœæ] ãã¯ãªãã¯ããŸãã
-
ãã®äŸã§ã¯ãcodespace ãäœæãããã³ãã¬ãŒã ãªããžããªã«æ¢ã«éçºã³ã³ãããŒæ§æãå«ãŸããŠãããããæ§æãã¡ã€ã«ãæ¢ã«ååšããããšã瀺ãã¡ãã»ãŒãžã衚瀺ãããŸãã æ¢åã®æ§æãã¡ã€ã«ãäžæžãããã®ã§ã [ç¶è¡] ãã¯ãªãã¯ããŸãã
-
[ãã¹ãŠã®å®çŸ©ã衚瀺ãã] ãã¯ãªãã¯ããŸãã
-
ã
c#
ããšå ¥åã㊠[C# (.NET)] ãã¯ãªãã¯ããŸãã ãããžã§ã¯ãã§ç¹å®ã®ããŒã«ã䜿çšããŠããå Žåã¯ããã®ä»ã®ãªãã·ã§ã³ã䜿çšã§ããŸãã ããšãã°ãC# ãš MS SQL ã§ãã -
ãããžã§ã¯ãã«äœ¿çšãã .NET ã®ããŒãžã§ã³ãéžæããŸãã ãã®å Žåã¯ã"(æ¢å®å€)" ãšããŒã¯ãããããŒãžã§ã³ãéžæããŸãã
-
è¿œå æ©èœã®ãªã¹ãã衚瀺ãããŸãã .NET ã¢ããªã±ãŒã·ã§ã³ã®éçºããã«ããå®è¡ãçºè¡ãè¡ãã³ãã³ã ã©ã€ã³ ã€ã³ã¿ãŒãã§ã€ã¹ã§ãã .NET CLI ãã€ã³ã¹ããŒã«ããŸãã ãã®ããŒã«ãã€ã³ã¹ããŒã«ããã«ã¯ãã
dotnet
ããšå ¥åããDotnet CLI
ãéžãã§ [OK] ãã¯ãªãã¯ããŸãã -
éçºã³ã³ãããŒæ§æãã¡ã€ã«ãæ¢ã«ååšããããšã瀺ãã¡ãã»ãŒãžã衚瀺ãããŸãã [äžæžã] ãã¯ãªãã¯ããŸãã
devcontainer.json
ãã¡ã€ã«ãäœæããããšãã£ã¿ãŒã§éããŸãã
ã«ã¹ã¿ã éçºã³ã³ãããŒæ§æã®è©³çް
Visual Studio Code ãšã¯ã¹ãããŒã©ãŒãèŠããšãdevcontainer.json
ãã¡ã€ã«ãå«ããããžã§ã¯ãã®ãªããžããªã®ã«ãŒãã« .devcontainer
ãã£ã¬ã¯ããªã远å ãããŠããããšãããããŸãã ããã¯ããã®ãªããžããªããäœæããã codespace ã®ã¡ã€ã³æ§æãã¡ã€ã«ã§ãã
devcontainer.json
远å ãã devcontainer.json
ãã¡ã€ã«ã«ã¯ãname
ãimage
ãããã³ features
ããããã£ã®å€ãå«ãŸããŸãã 䟿å©ãªããããã£ãããã€ãå«ãŸããŠããŸãããã³ã¡ã³ãã¢ãŠããããŠããŸãã
éžãã ã€ã¡ãŒãžã«å¿ããŠããã¡ã€ã«ã¯æ¬¡ã®ããã«ãªããŸãã
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet
{
"name": "C# (.NET)",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/dotnet:0-7.0",
"features": {
"ghcr.io/devcontainers/features/dotnet:1": {}
}
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5000, 5001],
// "portsAttributes": {
// "5001": {
// "protocol": "https"
// }
// }
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "dotnet restore",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
- name: éçºã³ã³ãããŒã«ã¯ä»»æã®ååãä»ããããšãã§ããŸãã æ¢å®å€ãæå®ãããŠããŸãã
- image: codespace ã®éçºã³ã³ãããŒã®äœæã«äœ¿ãããã³ã³ãã㌠ã¬ãžã¹ã㪠(DockerHubãGitHub Container registryããŸãã¯Azure Container Registry) å ã®ç»åã®ååã
- features: 1 ã€ä»¥äžã®ãªããžã§ã¯ãã®äžèЧãåãªããžã§ã¯ãã¯ã䜿çšå¯èœãªéçºã³ã³ãããŒæ©èœã®ãããããåç
§ããŸãã æ©èœãšã¯èªå·±å®çµåã§ãããã€ã³ã¹ããŒã« ã³ãŒããšéçºã³ã³ãããŒã®æ§æã®å
±æå¯èœãªãŠãããã§ãã ãããã¯ãéçºã³ã³ãããŒã«ããŒã«ãã©ã³ã¿ã€ã ããŸãã¯ã©ã€ãã©ãªã®æ©èœã远å ããç°¡åãªæ¹æ³ãæäŸããŸãã æ©èœè¿œå ã¯ãVS Code ãŸãã¯ãGitHub äžã®
devcontainer.json
ãšãã£ã¿ãŒã§è¡ããŸãã 詳现ã«ã€ããŠã¯ããdevcontainer.json ãã¡ã€ã«ãžã®æ©èœã®è¿œå ãã®ãVisual Studio CodeããŸãã¯ãWeb ãã©ãŠã¶ãŒãã¿ããã¯ãªãã¯ããŠãã ããã - forwardPorts - ããã«ãªã¹ããããŠããããŒãã¯ãã¹ãŠèªåçã«è»¢éãããŸãã 詳ããã¯ããcodespace ã§ã®ããŒãã®è»¢éããã芧ãã ããã
- portsAttributes - ãã®ããããã£ã¯ãæå®ãããããŒãã 1 ã€ä»¥äžã®æ¢å®ã®ãªãã·ã§ã³ã«ãããããŸãã 詳ããã¯ãéçºã³ã³ãããŒã® Web ãµã€ãã®éçºã³ã³ãããŒã®ä»æ§ãã芧ãã ããã
- postCreateCommand: codespace ãäœæãããåŸã«ã³ãã³ããå®è¡ããã«ã¯ããã®ããããã£ã䜿ããŸãã ããã¯ãæåå (äžèšã®ãšãã)ãé åããŸãã¯ãªããžã§ã¯ããšããŠæžåŒèšå®ã§ããŸãã 詳ããã¯ãéçºã³ã³ãããŒã® Web ãµã€ãã®éçºã³ã³ãããŒã®ä»æ§ãã芧ãã ããã
- customizations: ãã®ããããã£ã䜿çšãããšãcodespace ã§ã®äœæ¥ã«äœ¿çšãããå Žåãç¹å®ã®ããŒã«ãŸãã¯ãµãŒãã¹ãã«ã¹ã¿ãã€ãºã§ããŸãã ããšãã°ãVS Code ã®ç¹å®ã®èšå®ãšæ¡åŒµæ©èœãæ§æã§ããŸãã 詳现ã«ã€ããŠã¯ãéçºã³ã³ãã㌠Web ãµã€ãã®ããµããŒã ããŒã«ãšãµãŒãã¹ããåç §ããŠãã ããã
- remoteUser: æ¢å®ã§ã¯ãvscode ãŠãŒã¶ãŒãšããŠå®è¡ãããŠããŸãããå¿ èŠã«å¿ããŠããã root ã«èšå®ããããšãã§ããŸãã
䜿çšå¯èœãªããããã£ã®å®å šãªäžèЧã«ã€ããŠã¯ãéçºã³ã³ãããŒã® Web ãµã€ãã®éçºã³ã³ãããŒã®ä»æ§ã«é¢ããããŒãžãåç §ããŠãã ããã
远å ã®éçºã³ã³ãããŒæ§æãã¡ã€ã«
Docker ã«æ
£ããŠããå Žåã¯ãDockerfile ãŸã㯠Docker Compose ã䜿çšããŠãdevcontainer.json
ãã¡ã€ã«ã«å ã㊠codespace ç°å¢ãæ§æã§ããŸãã ãããè¡ãã«ã¯ãdevcontainer.json
ãã¡ã€ã«ãšäžç·ã« Dockerfile
ãŸã㯠compose.yaml
ãã¡ã€ã«ã远å ããŸãã 詳现ã«ã€ããŠã¯ãéçºã³ã³ãã㌠Web ãµã€ãã®ãã€ã¡ãŒãžãDockerfilesãDocker Compose ã®äœ¿çšããåç
§ããŠãã ããã
ã¹ããã 3: devcontainer.json ãã¡ã€ã«ã倿Žãã
éçºã³ã³ãããŒã®æ§æã远å ãããã¹ãŠã®æ©èœãåºæ¬çã«çè§£ããã®ã§ã倿Žãè¡ã£ãŠç°å¢ãããã«ã«ã¹ã¿ãã€ãºã§ããŸãã ãã®äŸã§ã¯ã次ã®åäœãè¡ãããããã£ã远å ããŸãã
- ãªã¢ãŒã ãã·ã³ã§ã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããŠããããŒããããŒã«ã« ã³ã³ãã¥ãŒã¿ãŒã«è»¢éããŸãã
- éçºã³ã³ãããŒã®äœæåŸã«
dotnet restore
ãå®è¡ããŠãã¢ããªã±ãŒã·ã§ã³ã«å¿ èŠãªäŸåé¢ä¿ã埩å ããŸãã - ãã® codespace ã« VS Code æ¡åŒµæ©èœãèªåçã«ã€ã³ã¹ããŒã«ããŸãã
-
devcontainer.json
ãã¡ã€ã«ã§ãfeatures
ããããã£ã®åŸã«ã³ã³ãã远å ããæ©èœã«é¢ããã³ã¡ã³ãã¢ãŠãããã 2 ã€ã®è¡ãåé€ããŸããJSONC "features": { "ghcr.io/devcontainers/features/dotnet:1": {} }, // Features to add to the dev container. More info: https://containers.dev/features. // "features": {},
"features": { "ghcr.io/devcontainers/features/dotnet:1": {} }, // Features to add to the dev container. More info: https://containers.dev/features. // "features": {},
-
forwardPorts
ããããã£ãã³ã¡ã³ãè§£é€ãããã®å€ãããŒã5000
ã®ã¿ã«å€æŽããŸããJSONC // Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [5000],
// Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [5000],
-
postCreateCommand
ããããã£ãã³ã¡ã³ãè§£é€ããŸããJSONC // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "dotnet restore",
// Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "dotnet restore",
-
customizations
ããããã£ã®ã³ã¡ã³ããè§£é€ããæ¬¡ã®ããã«ç·šéããŠã"Code Spell Checker" VS Code æ¡åŒµæ©èœãã€ã³ã¹ããŒã«ããŸããJSONC // Configure tool-specific properties. "customizations": { // Configure properties specific to VS Code. "vscode": { // Add the IDs of extensions you want installed when the container is created. "extensions": [ "streetsidesoftware.code-spell-checker" ] } }
// Configure tool-specific properties. "customizations": { // Configure properties specific to VS Code. "vscode": { // Add the IDs of extensions you want installed when the container is created. "extensions": [ "streetsidesoftware.code-spell-checker" ] } }
éžãã ã€ã¡ãŒãžã«å¿ããŠã
devcontainer.json
ãã¡ã€ã«ã¯æ¬¡ã®ããã«ãªããŸãã// For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/dotnet { "name": "C# (.NET)", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile "image": "mcr.microsoft.com/devcontainers/dotnet:0-7.0", "features": { "ghcr.io/devcontainers/features/dotnet:1": {} }, // Use 'forwardPorts' to make a list of ports inside the container available locally. "forwardPorts": [5000], // "portsAttributes": { // "5001": { // "protocol": "https" // } // } // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "dotnet restore", // Configure tool-specific properties. "customizations": { // Configure properties specific to VS Code. "vscode": { // Add the IDs of extensions you want installed when the container is created. "extensions": [ "streetsidesoftware.code-spell-checker" ] } } // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" }
-
倿Žãä¿åããŸãã
-
VS Code Command Palette ã«ã¢ã¯ã»ã¹ (Shift+Command+P / Ctrl+Shift+P) ããããªãã«ãããšå ¥åããŸãã [Codespaces: ã³ã³ãããŒã®ãªãã«ã] ãã¯ãªãã¯ããŸãã
ãã³ã
ãã£ãã·ã¥ãã¯ãªã¢ããæ°ããã€ã¡ãŒãžã䜿çšããŠã³ã³ãããŒãåæ§ç¯ããããã«ãå®å šãªãªãã«ããå®è¡ããããšãå¿ èŠã«ãªãå ŽåããããŸãã 詳ããã¯ããcodespace ã§ã®ã³ã³ãããŒã®ãªãã«ãããã芧ãã ããã ãªããžããªã«å€æŽãã³ãããããåã«ãcodespace å ã§ãªãã«ãããããšã«ããæåŸ ã©ããã«å€æŽãåäœããŸãã äœããã®å€±æããã£ãå Žåãã³ã³ããã®èª¿æŽãç¶ç¶ããããã«ãªãã«ãã§ãããªã«ããªã³ã³ãããåãã codespace ã«é 眮ãããŸãã
éçºã³ã³ãããŒãåæ§ç¯ãããcodespace ãåã³äœ¿çšå¯èœã«ãªããšã
postCreateCommand
ãå®è¡ãããå¿ èŠãªäŸåé¢ä¿ã埩å ããã"Code Spell Checker" æ¡åŒµæ©èœã䜿çšã§ããããã«ãªããŸãã
æé 4:ã¢ããªã±ãŒã·ã§ã³ãå®è¡ãã
åã®ã»ã¯ã·ã§ã³ã§ã¯ãpostCreateCommand
ã䜿çšããŠãäžé£ã®ããã±ãŒãžã dotnet restore
ã³ãã³ãã䜿ã£ãŠã€ã³ã¹ããŒã«ããŸããã äŸåé¢ä¿ãã€ã³ã¹ããŒã«ãããããã¢ããªã±ãŒã·ã§ã³ãå®è¡ã§ããŸãã
-
ã¿ãŒããã«ã§
F5
ãæŒãããdotnet watch run
ãå ¥åããŠã¢ããªã±ãŒã·ã§ã³ãå®è¡ããŸãã -
ã¢ããªã±ãŒã·ã§ã³ãèµ·åãããã [ããŒã] ã¿ããã¯ãªãã¯ããããŒã 5000 ãå³ã¯ãªãã¯ãã [ãã©ãŠã¶ãŒã§éã] ãã¯ãªãã¯ããŸãã
ã¹ããã 5: 倿Žãã³ããããã
æ°ããã³ãŒãã§ãããæ§æã®å€æŽã§ãããcodespace ã«å€æŽãå ãããããã®å€æŽãã³ãããããããªãã§ãããã ãªããžããªã«æ§æã®å€æŽãã³ããããããšããã®ãªããžããªãã codespace ãäœæããä»ã®äººããåãæ§æã䜿çšããããã«ã§ããŸãã VS Code æ¡åŒµæ©èœã®è¿œå ãªã©ãè¡ããã¹ãŠã®ã«ã¹ã¿ãã€ãºããã¹ãŠã®ãŠãŒã¶ãŒã䜿ããããã«ãªããŸãã
ãã®ãã¥ãŒããªã¢ã«ã§ã¯ããã³ãã¬ãŒã ãªããžããªãã codespace ãäœæããã®ã§ãcodespace å ã®ã³ãŒãã¯ãŸã ãªããžããªã«æ ŒçŽãããŠããŸããã çŸåšã®ãã©ã³ãã GitHub ã«çºè¡ããããšã§ããªããžããªãäœæã§ããŸãã
詳ããã¯ããCodespace ã§ãœãŒã¹ã³ã³ãããŒã«ã䜿çšããããåç §ããŠãã ããã
次ã®ã¹ããã
ããã§ãç¬èªã® C# (.NET) ãããžã§ã¯ãã«ã«ã¹ã¿ã éçºã³ã³ãããŒæ§æã远å ã§ããããã«ãªããŸãã
ããé«åºŠãªã·ããªãªåãã®è¿œå ã®ãªãœãŒã¹ã¯æ¬¡ã®ãšããã§ãã