Skip to content

Commit bb607d6

Browse files
committed
Don't run MSBuild IoC registration if not actually in MSBuild
1 parent ce56906 commit bb607d6

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/React.MSBuild/AssemblyRegistration.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10+
using System.Diagnostics;
1011
using React.TinyIoC;
1112

1213
namespace React.MSBuild
@@ -23,6 +24,14 @@ public class AssemblyRegistration : IAssemblyRegistration
2324
/// <param name="container">Container to register components in</param>
2425
public void Register(TinyIoCContainer container)
2526
{
27+
if (!MSBuildHost.IsInMSBuild())
28+
{
29+
Trace.WriteLine(
30+
"Warning: React.MSBuild AssemblyRegistration called, but not currently in MSBuild!"
31+
);
32+
return;
33+
}
34+
2635
container.Register<ICache, NullCache>();
2736
container.Register<IFileSystem, SimpleFileSystem>();
2837
}

src/React.MSBuild/MSBuildHost.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
using System;
11+
using System.Diagnostics;
1112

1213
namespace React.MSBuild
1314
{
@@ -41,5 +42,21 @@ private static bool Initialize()
4142

4243
return true;
4344
}
45+
46+
/// <summary>
47+
/// Determines if the current process is MSBuild
48+
/// </summary>
49+
/// <returns><c>true</c> if we are currently in MSBuild</returns>
50+
public static bool IsInMSBuild()
51+
{
52+
try
53+
{
54+
return Process.GetCurrentProcess().ProcessName.StartsWith("MSBuild");
55+
}
56+
catch (Exception)
57+
{
58+
return false;
59+
}
60+
}
4461
}
4562
}

0 commit comments

Comments
 (0)