Skip to content

Commit

Permalink
Merge pull request #252 from filipw/bugfix/226
Browse files Browse the repository at this point in the history
Read DefineConstants from MsBuild file
  • Loading branch information
nosami committed Jun 30, 2015
2 parents 25eae94 + f0648ff commit dc21b16
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/OmniSharp/MSBuild/MSBuildProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,15 @@ private void UpdateProject(ProjectFileInfo projectFileInfo)
}
}

if (projectFileInfo.SpecifiedLanguageVersion.HasValue)
if (projectFileInfo.SpecifiedLanguageVersion.HasValue || projectFileInfo.DefineConstants != null)
{
var parseOptions = new CSharpParseOptions(projectFileInfo.SpecifiedLanguageVersion.Value);
var parseOptions = projectFileInfo.SpecifiedLanguageVersion.HasValue
? new CSharpParseOptions(projectFileInfo.SpecifiedLanguageVersion.Value)
: new CSharpParseOptions();
if (projectFileInfo.DefineConstants != null && projectFileInfo.DefineConstants.Any())
{
parseOptions.WithPreprocessorSymbols(projectFileInfo.DefineConstants);
}
_workspace.SetParseOptions(project.Id, parseOptions);
}

Expand Down
22 changes: 15 additions & 7 deletions src/OmniSharp/MSBuild/ProjectFile/ProjectFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ public class ProjectFileInfo

public LanguageVersion? SpecifiedLanguageVersion { get; private set; }

public string ProjectDirectory
{
get
{
return Path.GetDirectoryName(ProjectFilePath);
}
}
public string ProjectDirectory => Path.GetDirectoryName(ProjectFilePath);

public string AssemblyName { get; private set; }

Expand All @@ -51,6 +45,8 @@ public string ProjectDirectory

public IList<string> Analyzers { get; private set; }

public IList<string> DefineConstants { get; private set; }

public static ProjectFileInfo Create(MSBuildOptions options, ILogger logger, string solutionDirectory, string projectFilePath, ICollection<MSBuildDiagnosticsMessage> diagnostics)
{
var projectFileInfo = new ProjectFileInfo();
Expand Down Expand Up @@ -115,6 +111,12 @@ public static ProjectFileInfo Create(MSBuildOptions options, ILogger logger, str
projectInstance.GetItems("Analyzer")
.Select(p => p.GetMetadataValue("FullPath"))
.ToList();

var defineConstants = projectInstance.GetPropertyValue("DefineConstants");
if (!string.IsNullOrWhiteSpace(defineConstants))
{
projectFileInfo.DefineConstants = defineConstants.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
}
}
else
{
Expand Down Expand Up @@ -181,6 +183,12 @@ public static ProjectFileInfo Create(MSBuildOptions options, ILogger logger, str
projectFileInfo.Analyzers = itemsLookup["Analyzer"]
.Select(p => Path.GetFullPath(Path.Combine(projectFileInfo.ProjectDirectory, p.FinalItemSpec)))
.ToList();

var defineConstants = properties["DefineConstants"].FinalValue;
if (!string.IsNullOrWhiteSpace(defineConstants))
{
projectFileInfo.DefineConstants = defineConstants.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
}
}
#else
// TODO: Shell out to msbuild/xbuild here?
Expand Down

0 comments on commit dc21b16

Please sign in to comment.