44using System . Collections . Generic ;
55using System . IO ;
66using System . Linq ;
7+ using System . Reflection ;
78using System . Text ;
89using System . Threading . Tasks ;
910
@@ -28,7 +29,7 @@ private static async Task genCSharpCode(string instructionId, string typeFullNam
2829 //如果没有属性,产生类
2930 if ( schema . Properties . Count == 0 )
3031 {
31- sb . Insert ( code . Length - 3 , $ "public class { typeInfo . TypeName } { Environment . NewLine } {{{Environment.NewLine}}}") ;
32+ sb . Insert ( code . Length - 2 , $ "public partial class { typeInfo . TypeName } { Environment . NewLine } {{{Environment.NewLine} }}") ;
3233 }
3334
3435 //如果是命令请求类型
@@ -66,6 +67,9 @@ private static async Task genCSharpCode(string instructionId, string typeFullNam
6667
6768 public static async Task Generate ( QpInstruction instruction , string folder )
6869 {
70+ if ( ! Directory . Exists ( folder ) )
71+ Directory . CreateDirectory ( folder ) ;
72+
6973 //生成通知类代码
7074 if ( instruction . NoticeInfos != null && instruction . NoticeInfos . Length > 0 )
7175 {
@@ -96,7 +100,7 @@ public static async Task Generate(QpInstruction instruction, string folder)
96100 sbInstruction . AppendLine ( " public static QpInstruction Instance = new QpInstruction()" ) ;
97101 sbInstruction . AppendLine ( " {" ) ;
98102 sbInstruction . AppendLine ( " Id = typeof(Instruction).Namespace," ) ;
99- sbInstruction . AppendLine ( $ " Name = { instruction . Name } ,") ;
103+ sbInstruction . AppendLine ( $ " Name = \" { instruction . Name } \" ,") ;
100104 if ( instruction . NoticeInfos != null && instruction . NoticeInfos . Length > 0 )
101105 {
102106 sbInstruction . AppendLine ( " NoticeInfos = new[]" ) ;
@@ -130,6 +134,21 @@ public static async Task Generate(QpInstruction instruction, string folder)
130134 sbInstruction . AppendLine ( " }" ) ;
131135 sbInstruction . AppendLine ( "}" ) ;
132136 File . WriteAllText ( Path . Combine ( folder , "Instruction.cs" ) , sbInstruction . ToString ( ) ) ;
137+ var qpVersion = typeof ( QpChannel ) . Assembly . GetCustomAttribute < AssemblyInformationalVersionAttribute > ( ) . InformationalVersion ;
138+ File . WriteAllText ( Path . Combine ( folder , instruction . Id + ".csproj" ) , @$ "
139+ <Project Sdk=""Microsoft.NET.Sdk"">
140+
141+ <PropertyGroup>
142+ <TargetFramework>netstandard2.0</TargetFramework>
143+ </PropertyGroup>
144+
145+ <ItemGroup>
146+ <PackageReference Include=""Quick.Protocol"" Version=""{ qpVersion } "" />
147+ </ItemGroup>
148+
149+ </Project>
150+ " ) ;
151+
133152 }
134153 }
135154}
0 commit comments