@@ -178,6 +178,7 @@ class CSharpConfig:
178
178
def __init__ (self , config : Dict [str , Any ]) -> None :
179
179
root = config .get ('languages' , {}).get ('csharp' , {})
180
180
self .static_embedding : Optional [str ] = root .get ('static_embedding' , None )
181
+ self .csproj_template : Optional [str ] = root .get ('csproj_template' , None )
181
182
182
183
183
184
class CSharpLanguageEnvironment (LanguageEnvironment ):
@@ -186,16 +187,30 @@ def __init__(self, config: CSharpConfig) -> None:
186
187
self .config = config
187
188
188
189
@staticmethod
189
- def _create_runner_project (code : bytes , target_framework : str , output_dir ):
190
- os .makedirs (str (output_dir ), exist_ok = True )
191
- with open (output_dir / 'runner.csproj' , 'w' ) as f :
190
+ def _write_default_project (output_file : pathlib .Path , target_framework : str ) -> None :
191
+ with open (output_file , 'w' ) as f :
192
192
f .write ('''<Project Sdk="Microsoft.NET.Sdk">
193
193
<PropertyGroup>
194
194
<OutputType>Exe</OutputType>
195
195
<TargetFramework>{}</TargetFramework>
196
196
</PropertyGroup>
197
197
</Project>''' .format (target_framework ))
198
198
199
+ def _write_csproj (self , output_file : pathlib .Path , target_framework : str ) -> None :
200
+ if self .config .csproj_template is None :
201
+ self ._write_default_project (output_file , target_framework )
202
+ return
203
+ csproj_template_path = pathlib .Path (self .config .csproj_template )
204
+ if not csproj_template_path .exists ():
205
+ logger .warning ('%s is not found.' , self .config .csproj_template )
206
+ self ._write_default_project (output_file , target_framework )
207
+ return
208
+
209
+ shutil .copy (str (csproj_template_path ), str (output_file ))
210
+
211
+ def _create_runner_project (self , code : bytes , target_framework : str , output_dir ):
212
+ os .makedirs (str (output_dir ), exist_ok = True )
213
+ self ._write_csproj (output_dir / 'runner.csproj' , target_framework )
199
214
with open (output_dir / 'main.cs' , 'wb' ) as f :
200
215
f .write (code )
201
216
0 commit comments