@@ -81,10 +81,11 @@ public object Load(string[] pathArray, string name, string nameSpace = "ORTS.Scr
81
81
82
82
private static Assembly CompileScript ( string [ ] path )
83
83
{
84
+ var scriptPath = path . Length > 1 ? Path . GetDirectoryName ( path [ 0 ] ) : path [ 0 ] ;
85
+ var scriptName = Path . GetFileName ( scriptPath ) ;
84
86
try
85
87
{
86
- var scriptName = Path . GetFileName ( path [ 0 ] ) ;
87
- var syntaxTrees = path . Select ( file => CSharpSyntaxTree . ParseText ( File . ReadAllText ( file ) ) ) ;
88
+ var syntaxTrees = path . Select ( file => CSharpSyntaxTree . ParseText ( File . ReadAllText ( file ) , null , file ) ) ;
88
89
var compilation = CSharpCompilation . Create (
89
90
scriptName ,
90
91
syntaxTrees ,
@@ -99,23 +100,26 @@ private static Assembly CompileScript(string[] path)
99
100
// in netcore:
100
101
//var script = AssemblyLoadContext.Default.LoadFromStream(ms);
101
102
if ( script == null )
102
- Trace . TraceWarning ( $ "Script file { path } could not be loaded into the process.") ;
103
+ Trace . TraceWarning ( $ "Script { scriptPath } could not be loaded into the process.") ;
103
104
return script ;
104
105
}
105
106
else
106
107
{
107
108
var errors = result . Diagnostics . Where ( diagnostic => diagnostic . IsWarningAsError || diagnostic . Severity == DiagnosticSeverity . Error ) ;
108
109
109
110
var errorString = new StringBuilder ( ) ;
110
- errorString . AppendFormat ( "Skipped script {0} with error:" , path ) ;
111
+ errorString . AppendFormat ( "Skipped script {0} with error:" , scriptPath ) ;
111
112
errorString . Append ( Environment . NewLine ) ;
112
113
foreach ( var error in errors )
113
114
{
114
115
var textSpan = error . Location . SourceSpan ;
116
+ var fileName = Path . GetFileName ( error . Location . SourceTree . FilePath ) ;
115
117
var lineSpan = error . Location . SourceTree . GetLineSpan ( textSpan ) ;
116
118
var line = lineSpan . StartLinePosition . Line + 1 ;
117
119
var column = lineSpan . StartLinePosition . Character ;
118
- errorString . AppendFormat ( "\t {0}: {1}, line: {2}, column: {3}" , error . Id , error . GetMessage ( ) , line , column ) ;
120
+ errorString . AppendFormat ( "\t {0}: {1}, " , error . Id , error . GetMessage ( ) ) ;
121
+ if ( path . Length > 1 ) errorString . AppendFormat ( "file: {0}, " , fileName ) ;
122
+ errorString . AppendFormat ( "line: {0}, column: {1}" , line , column ) ;
119
123
errorString . Append ( Environment . NewLine ) ;
120
124
}
121
125
@@ -125,18 +129,15 @@ private static Assembly CompileScript(string[] path)
125
129
}
126
130
catch ( InvalidDataException error )
127
131
{
128
- if ( path . Length > 1 )
129
- Trace . TraceWarning ( "Skipped script folder {0} with error: {1}" , Path . GetDirectoryName ( path [ 0 ] ) , error . Message ) ;
130
- else
131
- Trace . TraceWarning ( "Skipped script {0} with error: {1}" , path [ 0 ] , error . Message ) ;
132
+ Trace . TraceWarning ( "Skipped script {0} with error: {1}" , scriptPath , error . Message ) ;
132
133
return null ;
133
134
}
134
135
catch ( Exception error )
135
136
{
136
- if ( File . Exists ( path [ 0 ] ) )
137
- Trace . WriteLine ( new FileLoadException ( path [ 0 ] , error ) ) ;
137
+ if ( File . Exists ( scriptPath ) || Directory . Exists ( scriptPath ) )
138
+ Trace . WriteLine ( new FileLoadException ( scriptPath , error ) ) ;
138
139
else
139
- Trace . TraceWarning ( "Ignored missing script file {0}" , path [ 0 ] ) ;
140
+ Trace . TraceWarning ( "Ignored missing script {0}" , scriptPath ) ;
140
141
return null ;
141
142
}
142
143
}
0 commit comments