@@ -13,6 +13,8 @@ namespace NUnit.Engine.Internal
1313{
1414 internal class AddinsFile : List < AddinsFileEntry >
1515 {
16+ static readonly Logger log = InternalTrace . GetLogger ( typeof ( AddinsFile ) ) ;
17+
1618 public static AddinsFile Read ( IFile file )
1719 {
1820 if ( file == null )
@@ -33,29 +35,55 @@ public static AddinsFile Read(IFile file)
3335 /// <remarks>If the executing system uses backslashes ('\') to separate directories, these will be substituted with slashes ('/').</remarks>
3436 internal static AddinsFile Read ( Stream stream , string fullName = null )
3537 {
38+ // Read the whole file first
39+ var content = new List < string > ( ) ;
3640 using ( var reader = new StreamReader ( stream ) )
41+ {
42+ while ( ! reader . EndOfStream )
43+ content . Add ( reader . ReadLine ( ) . Trim ( ) ) ;
44+ }
45+
46+ // Create an empty AddinsFile, with no entries
47+ var addinsFile = new AddinsFile ( ) ;
48+
49+ // Ensure that this is actually an NUnit .addins file, since
50+ // the extension is used by others. See, for example,
51+ // https://github.com/nunit/nunit-console/issues/1761
52+ // TODO: Consider using an extension specific to NUnit for V4
53+ if ( ! IsNUnitAddinsFile ( content ) )
3754 {
38- var addinsFile = new AddinsFile ( ) ;
55+ log . Warning ( $ "Ignoring file { fullName } because it's not an NUnit .addins file") ;
56+ return addinsFile ;
57+ }
3958
40- int lineNumber = 0 ;
41- while ( ! reader . EndOfStream )
59+ // It's our file, so process it
60+ int lineNumber = 0 ;
61+ foreach ( var line in content )
62+ {
63+ var entry = new AddinsFileEntry ( ++ lineNumber , line ) ;
64+ if ( entry . Text != "" && ! entry . IsValid )
4265 {
43- var entry = new AddinsFileEntry ( ++ lineNumber , reader . ReadLine ( ) ) ;
44- if ( entry . Text != "" && ! entry . IsValid )
45- {
46- string msg = $ "Invalid Entry in { fullName ?? "addins file" } :\r \n { entry } ";
47- throw new InvalidOperationException ( msg ) ;
48- }
49-
50- addinsFile . Add ( entry ) ;
66+ string msg = $ "Invalid Entry in { fullName ?? "addins file" } :\r \n { entry } ";
67+ throw new InvalidOperationException ( msg ) ;
5168 }
5269
53- return addinsFile ;
70+ addinsFile . Add ( entry ) ;
5471 }
72+
73+ return addinsFile ;
5574 }
5675
5776 private AddinsFile ( ) { }
5877
78+ private static bool IsNUnitAddinsFile ( List < string > content )
79+ {
80+ foreach ( var line in content )
81+ if ( line . Length > 0 && line [ 0 ] == '<' )
82+ return false ;
83+
84+ return true ;
85+ }
86+
5987 public override string ToString ( )
6088 {
6189 var sb = new StringBuilder ( "AddinsFile:" ) ;
0 commit comments