关于MSBuild和NSwag的深入学习

这段时间学习一个整洁架构的开源项目,这是一名澳大利亚的软件架构师在github上面分享的项目:https://github.com/jasontaylordev/CleanArchitecture 作者的架构根底扎实,而且能灵活运用各种最新最简洁的技术知识,这个项目就用到非常多,我把代码pull下来之后发现直接编译过程中出了不少错误,花了两天时间都解决了。其中很大一部分是关于前端项目的内容,作者直接使用MSBuild来完成打包和创建,这只是我第一次看到。 另外还通过NSwag.MSBuild完成Open API代码的生成和typescript代码生成(运用于Angular),其中一个让我很惊讶的是:他居然在项目编译的时候初始化了数据库,弄得我云里雾里。我修改连接字符串,从报错信息才知道是执行这部分脚本的时候,MSWage的内核里初始化了Core的项目,调用到了初始化数据库代码: Executing file ‘config.nswag’ with variables ‘Configuration=Debug’… C:\Users\csuma.nuget\packages\nswag.msbuild\14.0.7\tools\Net80 下面是报错信息: Error NSwag command line tool for .NET Core Net80, toolchain v14.0.7.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0));Visit http://NSwag.org for more information.;NSwag bin directory: C:\Users\csuma.nuget\packages\nswag.msbuild\14.0.7\tools\Net80;Executing file ‘config.nswag’ with variables ‘Configuration=Debug’…;Launcher directory: C:\Users\csuma.nuget\packages\nswag.msbuild\14.0.7\tools\Net80;fail: CleanArchitecture.Infrastructure.Data.ApplicationDbContextInitialiser[0];An error occurred while initialising the database.;Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.<>cDisplayClass20_0.<b0>d.MoveNext();— End of stack trace from previous location —;at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerDatabaseCreator.<>cDisplayClass20_0.<b0>d.MoveNext();— End of stack trace from previous location —;at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken);at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.ExistsAsync(CancellationToken cancellationToken);at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken);at CleanArchitecture.Infrastructure.Data.ApplicationDbContextInitialiser.InitialiseAsync() in D:\project\CleanArchitecture\CleanArchitecture-main\CleanArchitecture-main\src\Infrastructure\Data\ApplicationDbContextInitialiser.cs:line 46;at CleanArchitecture.Infrastructure.Data.InitialiserExtensions.InitialiseDatabaseAsync(WebApplication app) in D:\project\CleanArchitecture\CleanArchitecture-main\CleanArchitecture-main\src\Infrastructure\Data\ApplicationDbContextInitialiser.cs:line 21;at Program. ...

June 4, 2024

命令行执行NSwag

Important for .NET Core: Assembly loading#net-core To use the command line tool nswag.exe (.NET 4.6+) / dotnet-nswag.dll (.NET Core), choose one of the following methods: NSwag NPM Module: Bindings for the .NET 4.6+ and .NET Core command line tools (depending on installed framework/OS platform) Download latest NSwagStudio MSI installer or install package NSwagStudio via Chocolatey: After installing the application, the path to the nswag.exe binary is registered in the PATH variable so that the tool can be used in the Windows command line. Download the latest command line tools: Extract the ZIP archive and use the nswag.exe binary in the Windows command line. NSwag.MSBuild NuGet package To see all available commands and parameters, run the command line application “nswag.exe” without parameters and enter “help” as command. All “input” parameters accept file paths, URLs and JSON data. ...

June 4, 2024

解决ng : 无法将“ng”项识别为 cmdlet、函数、脚本文件或可运行程序的名称及ng : 无法加载文件npm g.ps1问题

解决ng : 无法将“ng”项识别为 cmdlet、函数、脚本文件或可运行程序的名称 及 ng : 无法加载文件 C:\Users\15762\AppData\Roaming\npm\ng.ps1问题 ng : 无法将“ng”项识别为 cmdlet、函数、脚本文件或可运行程序的名称 解决 在命令行执行npm install -g @angular/cli ng : 无法加载文件 C:\Users\15762\AppData\Roaming\npm\ng.ps1 解决 以管理员身份运行Windows PowerShell,输入set-ExecutionPolicy RemoteSigned 选择是选择 A ng : 无法将“ng”项识别为 cmdlet、函数、脚本文件或可运行程序的名称 解决 在命令行执行npm install -g @angular/cli ng : 无法加载文件 C:\Users\15762\AppData\Roaming\npm\ng.ps1 解决 以管理员身份运行Windows PowerShell,输入set-ExecutionPolicy RemoteSigned 选择是选择 A

June 3, 2024

使用Visual Studio 2022 中的 .http 文件, ASP.NET Core API快速测试

Visual Studio 2022.http 文件编辑器提供了一种便捷的方式来测试 ASP.NET Core项目,尤其是 API 应用。 编辑器提供一个 UI,用于: 创建和更新 .http 文件。 发送 .http 文件中指定的 HTTP 请求。 显示响应。 本文包含以下文档: .http 文件语法。 如何创建 .http 文件。 如何从 .http 文件发送请求。 在何处查找可配置的 .http 文件选项。 如何使用 Visual Studio 2022 终结点资源管理器在 .http 文件中创建请求。 .http 文件格式和编辑器受 Visual Studio Code REST 客户端扩展的启发。 Visual Studio 2022 .http 编辑器将 .rest 识别为相同文件格式的替代文件扩展名。 先决条件 安装了“ASP.NET 和 Web 部署”工作负载的 Visual Studio 2022 版本 17.8 或更高版本。 .http 文件语法 以下部分介绍 .http 文件语法。 请求 HTTP 请求的格式为 HTTPMethod URL HTTPVersion,全部在一行上,其中: ...

June 1, 2024

Orchard Core 中文文档

Orchard Core 是基于 Orchard CMS 使用 ASP.NET Core 重新构建的。 Orchard Core 由两个不同的目标组成: Orchard Core Framework: 一个应用程序框架,用于构建模块化、多租户 的ASP.NET Core应用程序。 Orchard Core CMS: 一个建立在Orchard Core Framework之上的网络内容管理系统(CMS)。 需要注意框架和 CMS 之间的差异非常重要。一些想要开发 SaaS 应用程序的开发人员只会对模块化框架感兴趣。其他想要构建可管理网站的用户将专注于 CMS 并构建模块来增强其网站或整个生态系统。 Building Software as a Service (SaaS) solutions with the Orchard Core Framework 了解Orchard Core Framework是独立于nuget.org上的CMS分发的,这一点非常重要。我们在 https://github.com/OrchardCMS/OrchardCore.Samples 提供了一些示例程序,它将指导您如何仅使用Orchard Core Framework来构建模块化 和 多租户 的应用程序,而无需任何 CMS 特定功能。 我们的目标之一是启用托管应用程序的基于社区的生态系统,这些生态系统可以通过模块(如电子商务系统、博客引擎等)进行扩展。Orchard Core Framework支持模块化环境,允许不同的团队处理应用程序的不同部分,并使组件跨项目可重用。 B站演示视频:https://www.bilibili.com/video/BV17T4y177fW/ 使用Orchard Core CMS 构建网站 Orchard Core CMS 是基于Orchard CMS 使用ASP.NET Core 重写的。它不仅仅是一个端口,因为我们希望大幅提高性能,并尽可能与的ASP.NET Core 的开发模型一致。 ...

May 10, 2024

苍鹭与少年,宫崎骏的坚持

看完了《你想活出怎样的人生》,从内容上来看,这部电影的核心仍然是人文主义关怀、关于战后创伤与现代新国家的重建,当然也带有上世纪知识分子对过去挥之不去的烙印。吉卜力的动画片其实更多是拍给大人们看的,宫崎骏一直没有放弃自己坚持的理念:和平主义(反思战争和反对一切战争)、女性主义(主角大都是独立勇敢自由的女孩)和人与自然平等共存。 这次宫崎骏老爷爷因为身体原因不能去奥斯卡领奖,看来这部动画大概率真的会是他的封笔之作。老爷爷从始至终都坚持完全手绘制作动画的模式,这种方式成本极高,但是制作出来的动画相当逼真。这种创作动画的手法,民国时期的万氏兄弟曾经引领亚洲,其实日本的动画最开始是受中国影响,日本动画大师手冢治虫曾说他正是看了万氏兄弟的《铁扇公主》动画片后放弃学医,决定从事动画创作,手冢治虫算是宫崎骏的上一辈。只是后来中国突降人祸,形成了几十年的文化断层,日本一直沿着这条路坚持走到了今天,获得了巨大成功和全世界的尊重。 大约在二十年前,我们一起第一次看吉卜力的动画片《千与千寻》,这是他们工作室第一部获得奥斯卡最佳动画的作品,后来我们看完了吉卜力出品的大部分动画,并收藏了喜欢的蓝光,家里还有一本收集每部动画手绘底稿复印件的大部头书。前段时间我们两次东渡扶桑,特地去了一趟他们的美术馆,除了沉浸于吉卜力的梦幻世界,还看到了龙猫巴士爬行的电线杆原型、千寻神隐的神社痕迹和动画片背景里的各种现实场景。 日本是一个传统又时尚,保守又先进的多元化现代文明国家,只有你亲自去一趟才能深刻体会这种感觉,我在那里看到了本地朴质的文化与奢华的现代物质文化并肩存在,也看到了基督教、佛教和神道教各自蓬勃发展,更看到了古代中国的文化与现代文明交织成一个五彩斑斓的世界,太多的不想说,我真的认为:现在的日本(也许还有印度)是真正的神奇的东方文明古国。

April 18, 2024

《架构整洁之道》:Chap11. DIP: THE DEPENDENCY INVERSION PRINCIPLE DIP:依赖反转原则

The Dependency Inversion Principle (DIP) tells us that the most flexible systems are those in which source code dependencies refer only to abstractions, not to concretions. 依赖反转原则(DIP)主要想告诉我们的是,如果想要设计一个灵活的系统,在源代码层次的依赖关系中就应该多引用抽象类型,而用具体实现。 In a statically typed language, like Java, this means that the use, import, and include statements should refer only to source modules containing interfaces, abstract classes, or some other kind of abstract declaration. Nothing concrete should be depended on. 也就是说,在 Java 这类静态类型的编程语言中,在使用 use、import、include 这些语句时应该只引用那些包含接口、抽象类或者其他抽象类型声明的源文件,不应该引用任何具体实现。 ...

March 14, 2024

《架构整洁之道》:Chap10. ISP: THE INTERFACE SEGREGATION PRINCIPLE ISP:接口隔离原则

The Interface Segregation Principle (ISP) derives its name from the diagram shown in Figure 10.1. “接口隔离原则(ISP)”这个名字来自图 10.1 所示的这种软件结构。 The Interface Segregation Principle In the situation illustrated in Figure 10.1, there are several users who use the operations of the OPS class. Let’s assume that User1 uses only op1, User2 uses only op2, and User3 uses only op3. 在图 10.1 所描绘的应用中,有多个用户需要操作 OPS 类。现在,我们假设这里的 User1 只需要使用 op1,User2 只需要使用 op2,User3 只需要使用 op3。 Now imagine that OPS is a class written in a language like Java. Clearly, in that case, the source code of User1 will inadvertently depend on op2 and op3, even though it doesn’t call them. This dependence means that a change to the source code of op2 in OPS will force User1 to be recompiled and redeployed, even though nothing that it cared about has actually changed. ...

March 13, 2024

《架构整洁之道》:Chap9. LSP: THE LISKOV SUBSTITUTION PRINCIPLE LSP:里氏替换原则

In 1988, Barbara Liskov wrote the following as a way of defining subtypes. 1988 年,Barbara Liskov 在描述如何定义子类型时写下了这样一段话: What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T.1 ...

March 12, 2024

《架构整洁之道》:Chap8. OCP: THE OPEN-CLOSED PRINCIPLE OCP:开闭原则

The Open-Closed Principle (OCP) was coined in 1988 by Bertrand Meyer.1 It says: 开闭原则(OCP)是 Bertrand Meyer 在 1988 年提出的,该设计原则认为: A software artifact should be open for extension but closed for modification. 设计良好的计算机软件应该易于扩展,同时抗拒修改。 In other words, the behavior of a software artifact ought to be extendible, without having to modify that artifact. 换句话说,一个设计良好的计算机系统应该在不需要修改的前提下就可以轻易被扩展。 This, of course, is the most fundamental reason that we study software architecture. Clearly, if simple extensions to the requirements force massive changes to the software, then the architects of that software system have engaged in a spectacular failure. ...

March 11, 2024