{"id":21055855,"url":"https://github.com/startdusk/commandapisolution","last_synced_at":"2026-04-27T15:31:52.084Z","repository":{"id":140762460,"uuid":"423030918","full_name":"startdusk/CommandAPISolution","owner":"startdusk","description":".NET Core API Demo","archived":false,"fork":false,"pushed_at":"2021-11-08T14:03:10.000Z","size":66,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-01T14:38:03.845Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/startdusk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-31T02:00:03.000Z","updated_at":"2021-11-08T14:03:12.000Z","dependencies_parsed_at":"2024-09-03T04:00:59.350Z","dependency_job_id":null,"html_url":"https://github.com/startdusk/CommandAPISolution","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/startdusk/CommandAPISolution","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/startdusk%2FCommandAPISolution","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/startdusk%2FCommandAPISolution/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/startdusk%2FCommandAPISolution/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/startdusk%2FCommandAPISolution/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/startdusk","download_url":"https://codeload.github.com/startdusk/CommandAPISolution/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/startdusk%2FCommandAPISolution/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32343198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T16:47:32.330Z","updated_at":"2026-04-27T15:31:52.058Z","avatar_url":"https://github.com/startdusk.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CommandAPISolution\r\n\r\n.NET Core API Demo\r\n\r\n### 1.创建目录结构\r\n\r\n```bash\r\n$ mkdir CommandAPISolution\r\n$ cd CommandAPISolution\r\n$ mkdir src\r\n$ mkdir test\r\n```\r\n\r\n这里使用 sln 的方式，sln 可以集成多个 project，src 放 Source Code，test 放 Unit test\r\n\r\n### 2.创建项目\r\n\r\n```bash\r\n$ cd src\r\n$ dotnet new web -n CommandAPI # 这里使用web是想手动敲代码，实际开发中可一直接用webapi生成代码\r\n\r\n$ cd test\r\n$ dotnet new xunit -n CommandAPI.Tests\r\n```\r\n\r\n### 3.创建 Solution 关联 Project\r\n\r\n```bash\r\n$ cd ../\r\n$ dotnet new sln --name CommandAPISolution\r\n\r\n$ dotnet sln CommandAPISolution.sln add src/CommandAPI/CommandAPI.csproj test/CommandAPI.Tests/CommandAPI.Tests.csproj\r\n```\r\n\r\n### 4.关联 Source Code 和 Unit Test\r\n\r\n推荐使用命令行\r\n\r\n```bash\r\n$ dotnet add test/CommandAPI.Tests/CommandAPI.Tests.csproj reference src/CommandAPI/CommandAPI.csproj\r\n```\r\n\r\n或者直接在 test/CommandAPT.Tests/CommandAPI.Tests.csproj 文件中添加\r\n\r\n```xml\r\n\u003cItemGroup\u003e\r\n  \u003cProjectReference Include=\"..\\..\\src\\CommandAPI\\CommandAPI.csproj\" /\u003e\r\n\u003c/ItemGroup\u003e\r\n```\r\n\r\n### 5.编译 sln 是否正确运行, 根目录下运行\r\n\r\n```bash\r\n$ dotnet build\r\n```\r\n\r\n### 6. ASPNET 读取配置文件的顺序\r\n\r\n```bash\r\nappsetting.json -\u003e appsetting.Development.json -\u003e Secrets.json -\u003e Environment Variables -\u003e Command Line Args\r\n\r\n```\r\n\r\n### 7.使用 Secret 管理隐私数据\r\n\r\n为什么要使用 Secret 呢，本地开发存放隐私数据在本地，不需要写在配置文件里面，避免提交的 git 上\r\n\r\nSecret 会在用户目录上生成一个 secrets.json 的文件存放我的隐私数据，然后本地开发程序可以通过 Configuration 读取到\r\n\r\n1.首先要在 项目的 csproj 文件的 PropertyGroup 里配置一个全局唯一序列号，方便程序加载的时候能够快速找到该文件，全局唯一序列号 UUID 可以用 VSCode 插件生成\r\n\r\n如：\r\n\r\n```xml\r\n\u003cUserSecretsId\u003e5ad6f641-e6c6-4cc7-be03-19db479916fd\u003c/UserSecretsId\u003e\r\n```\r\n\r\n2.设置要保存到本地的 Secret 的数据\r\n\r\n```bash\r\n$ dotnet user-secrets set \"UserID\" \"你的数据库用户名\"\r\n\r\n$ dotnet user-secrets set \"Password\" \"你的数据库用户的密码\"\r\n```\r\n\r\n3.可以在以下目录看到生成的 secrets.json 文件(非加密文件)，user_secrets_id 就是你在上面设置的 UUID\r\n\r\n- Windows: %APPDATA%\\Microsoft\\UserSecrets\\\u003cuser_secrets_id\u003e\\\r\n  secrets.json\r\n- Linux/OSX: ~/.microsoft/usersecrets/\u003cuser_secrets_id\u003e/\r\n  secrets.json\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstartdusk%2Fcommandapisolution","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstartdusk%2Fcommandapisolution","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstartdusk%2Fcommandapisolution/lists"}