@@ -178,6 +178,7 @@ class CSharpConfig:
178178 def __init__ (self , config : Dict [str , Any ]) -> None :
179179 root = config .get ('languages' , {}).get ('csharp' , {})
180180 self .static_embedding : Optional [str ] = root .get ('static_embedding' , None )
181+ self .csproj_template : Optional [str ] = root .get ('csproj_template' , None )
181182
182183
183184class CSharpLanguageEnvironment (LanguageEnvironment ):
@@ -186,16 +187,30 @@ def __init__(self, config: CSharpConfig) -> None:
186187 self .config = config
187188
188189 @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 :
192192 f .write ('''<Project Sdk="Microsoft.NET.Sdk">
193193 <PropertyGroup>
194194 <OutputType>Exe</OutputType>
195195 <TargetFramework>{}</TargetFramework>
196196 </PropertyGroup>
197197</Project>''' .format (target_framework ))
198198
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 )
199214 with open (output_dir / 'main.cs' , 'wb' ) as f :
200215 f .write (code )
201216
0 commit comments