Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 9c3fd24

Browse files
devgophermrward
authored andcommitted
Fix null ref when building a solution containing non-MSBuild project.
The TypeScript addin did not handle building when one of the projects was not an MSBuild project. Fixes #740
1 parent f291047 commit 9c3fd24

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/AddIns/BackendBindings/TypeScript/Project/Src/CompileTypeScriptFilesOnBuildAction.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,19 @@ public class CompileTypeScriptFilesOnBuildAction : CompileTypeScriptAction
4141
public void CompileFiles(IEnumerable<IProject> projects)
4242
{
4343
ClearOutputWindow();
44-
foreach (TypeScriptProject project in projects.Select(project => new TypeScriptProject(project))) {
44+
foreach (TypeScriptProject project in GetTypeScriptProjects(projects)) {
4545
if (project.CompileOnBuild) {
4646
CompileFiles(project);
4747
}
4848
}
4949
}
5050

51+
static IEnumerable<TypeScriptProject> GetTypeScriptProjects(IEnumerable<IProject> projects)
52+
{
53+
return projects.OfType<MSBuildBasedProject>()
54+
.Select(project => new TypeScriptProject(project));
55+
}
56+
5157
void CompileFiles(TypeScriptProject project)
5258
{
5359
FileName[] fileNames = project.GetTypeScriptFileNames().ToArray();

src/AddIns/BackendBindings/TypeScript/Project/Src/TypeScriptProject.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,15 @@ public IEnumerable<FileName> GetTypeScriptFileNames()
8888
.Select(item => item.FileName);
8989
}
9090

91+
bool HasMSBuildProject {
92+
get { return msbuildProject != null; }
93+
}
94+
9195
string GetStringProperty(BuildConfiguration buildConfig, string name, string defaultValue)
9296
{
97+
if (!HasMSBuildProject)
98+
return defaultValue;
99+
93100
string propertyValue = msbuildProject.GetProperty(buildConfig.Configuration, buildConfig.Platform, name);
94101
if (!String.IsNullOrEmpty(propertyValue)) {
95102
return propertyValue;
@@ -99,6 +106,9 @@ string GetStringProperty(BuildConfiguration buildConfig, string name, string def
99106

100107
bool GetBooleanProperty(BuildConfiguration buildConfig, string name, bool defaultValue)
101108
{
109+
if (!HasMSBuildProject)
110+
return defaultValue;
111+
102112
string propertyValue = msbuildProject.GetProperty(buildConfig.Configuration, buildConfig.Platform, name);
103113
return ConvertBooleanValue(propertyValue, defaultValue);
104114
}
@@ -119,6 +129,9 @@ void SetBooleanProperty(BuildConfiguration buildConfig, string name, bool value)
119129

120130
void SetStringProperty(BuildConfiguration buildConfig, string name, string value)
121131
{
132+
if (!HasMSBuildProject)
133+
return;
134+
122135
msbuildProject.SetProperty(
123136
buildConfig.Configuration,
124137
buildConfig.Platform,
@@ -130,12 +143,18 @@ void SetStringProperty(BuildConfiguration buildConfig, string name, string value
130143

131144
bool GetBooleanProperty(string name, bool defaultValue)
132145
{
146+
if (!HasMSBuildProject)
147+
return defaultValue;
148+
133149
string propertyValue = msbuildProject.GetEvaluatedProperty(name);
134150
return ConvertBooleanValue(propertyValue, defaultValue);
135151
}
136152

137153
string GetStringProperty(string name, string defaultValue)
138154
{
155+
if (!HasMSBuildProject)
156+
return defaultValue;
157+
139158
string propertyValue = msbuildProject.GetEvaluatedProperty(name);
140159
if (!String.IsNullOrEmpty(propertyValue)) {
141160
return propertyValue;

0 commit comments

Comments
 (0)