public MSBuildRuntimeEvaluationContext(IRuntimeInformation runtime) { if (runtime is Editor.Completion.NullRuntimeInformation) { return; } string binPath = MSBuildEscaping.ToMSBuildPath(runtime.BinPath); string toolsPath = MSBuildEscaping.ToMSBuildPath(runtime.ToolsPath); Convert("MSBuildExtensionsPath"); Convert("MSBuildExtensionsPath32"); Convert("MSBuildExtensionsPath64"); void Convert(string name) { if (runtime.SearchPaths.TryGetValue(name, out var vals)) { values[name] = new MSBuildPropertyValue(vals.ToArray()); } } values["MSBuildBinPath"] = binPath; values["MSBuildToolsPath"] = toolsPath; values["MSBuildToolsPath32"] = toolsPath; values["MSBuildToolsPath64"] = toolsPath; values["RoslynTargetsPath"] = $"{binPath}\\Roslyn"; values["MSBuildToolsVersion"] = runtime.ToolsVersion; values["VisualStudioVersion"] = "15.0"; values["MSBuildProgramFiles32"] = MSBuildEscaping.ToMSBuildPath(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)); values["MSBuildProgramFiles64"] = MSBuildEscaping.ToMSBuildPath(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)); var defaultSdksPath = runtime.SdksPath; if (defaultSdksPath != null) { values["MSBuildSDKsPath"] = MSBuildEscaping.ToMSBuildPath(defaultSdksPath, null); } //these are read from a config file and may be described in terms of other properties void Collapse(string name) { if (values.TryGetValue(name, out var val)) { values["name"] = val.Collapse(this); } } Collapse("MSBuildExtensionsPath"); Collapse("MSBuildExtensionsPath32"); Collapse("MSBuildExtensionsPath64"); }
public MSBuildFileEvaluationContext( IMSBuildEvaluationContext runtimeContext, string projectPath, string thisFilePath) { this.runtimeContext = runtimeContext ?? throw new ArgumentNullException(nameof(runtimeContext)); // this file path properties if (thisFilePath != null) { values["MSBuildThisFile"] = MSBuildEscaping.EscapeString(Path.GetFileName(thisFilePath)); values["MSBuildThisFileDirectory"] = MSBuildEscaping.ToMSBuildPath(Path.GetDirectoryName(thisFilePath)) + "\\"; //"MSBuildThisFileDirectoryNoRoot" is this actually used for anything? values["MSBuildThisFileExtension"] = MSBuildEscaping.EscapeString(Path.GetExtension(thisFilePath)); values["MSBuildThisFileFullPath"] = MSBuildEscaping.ToMSBuildPath(Path.GetFullPath(thisFilePath)); values["MSBuildThisFileName"] = MSBuildEscaping.EscapeString(Path.GetFileNameWithoutExtension(thisFilePath)); } if (projectPath == null) { return; } // project path properties string escapedProjectDir = MSBuildEscaping.ToMSBuildPath(Path.GetDirectoryName(projectPath)); values["MSBuildProjectDirectory"] = escapedProjectDir; // "MSBuildProjectDirectoryNoRoot" is this actually used for anything? values["MSBuildProjectExtension"] = MSBuildEscaping.EscapeString(Path.GetExtension(projectPath)); values["MSBuildProjectFile"] = MSBuildEscaping.EscapeString(Path.GetFileName(projectPath)); values["MSBuildProjectFullPath"] = MSBuildEscaping.ToMSBuildPath(Path.GetFullPath(projectPath)); values["MSBuildProjectName"] = MSBuildEscaping.EscapeString(Path.GetFileNameWithoutExtension(projectPath)); //don't have a better value, this is as good as anything values["MSBuildStartupDirectory"] = escapedProjectDir; //HACK: we don't get a usable value for this without real evaluation so hardcode 'obj' var projectExtensionsPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(projectPath), "obj")); values["MSBuildProjectExtensionsPath"] = MSBuildEscaping.ToMSBuildPath(projectExtensionsPath) + "\\"; }