Skip to content

Commit

Permalink
Updates to support Visual Studio 2019
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone committed Jun 5, 2019
1 parent 5202433 commit d8f490b
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 121 deletions.
4 changes: 4 additions & 0 deletions IceBuilder/DocumentEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ public int OnAfterAddFilesEx(int projectsLength, int filesLength, IVsProject[] p
}
}
}
catch (OperationCanceledException)
{
// Ignore, this could happen if the project is reloaded
}
catch (Exception ex)
{
Package.UnexpectedExceptionWarning(ex);
Expand Down
10 changes: 2 additions & 8 deletions IceBuilder/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public void InitializeProject(IVsProject project)
}
else
{
if (project is IVsAggregatableProject)
if (project is IVsAggregatableProject && !project.HasProjectFlavor(IceBuilderNewFlavor))
{
project.AddProjectFlavorIfNotExists(IceBuilderNewFlavor);
}
Expand Down Expand Up @@ -584,13 +584,7 @@ private void PackageInstalled()
var projects = DTEUtil.GetProjects();
foreach (IVsProject project in projects)
{
// Projects that are not being track has not been previous initialized
// initialize will do nothing if zeroc.icebuilder.msbuild package is
// not installed
if(project.IsMSBuildIceBuilderInstalled())
{
InitializeProject(project);
}
InitializeProject(project);
}
}

Expand Down
2 changes: 1 addition & 1 deletion IceBuilder/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<packages>
<package id="Microsoft.VisualStudio.SDK.Analyzers" version="15.8.36" targetFramework="net46" />
<package id="Microsoft.VisualStudio.Threading.Analyzers" version="15.8.168" targetFramework="net46" />
<package id="Microsoft.VSSDK.VsixSignTool" version="15.9.28307" targetFramework="net46" />
<package id="Microsoft.VSSDK.VsixSignTool" version="16.1.28916.169" targetFramework="net46" />
</packages>
10 changes: 9 additions & 1 deletion IceBuilder_Common/IVsProjectExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,21 @@ public static void SetItemMetadata(this IVsProject project, string name, string
ProjectFactoryHelperInstance.ProjectHelper.SetItemMetadata(project, name, value);
}

public static bool HasProjectFlavor(this IVsProject project, string flavor)
{
return project.WithProject((MSProject msproject) =>
{
return msproject.HasProjectFlavor(flavor);
}, true);
}

public static void AddProjectFlavorIfNotExists(this IVsProject project, string flavor)
{
ProjectFactoryHelperInstance.ProjectHelper.UpdateProject(project,
(MSProject msproject) =>
{
msproject.AddProjectFlavorIfNotExists(flavor);
});
}, true);
}

public static void RemoveGeneratedItemCustomMetadata(this IVsProject project, List<string> paths)
Expand Down
18 changes: 13 additions & 5 deletions IceBuilder_Common/MSProjectExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ namespace IceBuilder
{
public static class MSProjectExtension
{
static readonly ProjectCollection cppProjectColletion = new ProjectCollection();

public static Project LoadedProject(string path)
{
return ProjectCollection.GlobalProjectCollection.GetLoadedProjects(path).FirstOrDefault();
return ProjectCollection.GlobalProjectCollection.GetLoadedProjects(path).FirstOrDefault() ??
ProjectCollection.GlobalProjectCollection.LoadProject(path);
}

public static string GetItemMetadata(this Project project, string identity, string name, string defaultValue = "")
public static string GetItemMetadata(this Project project, string identity, string name,
string defaultValue = "")
{
var item = project.AllEvaluatedItems.FirstOrDefault(
i => i.ItemType.Equals("SliceCompile") && i.EvaluatedInclude.Equals(identity));
Expand All @@ -34,7 +34,8 @@ public static string GetItemMetadata(this Project project, string identity, stri
}
}

public static string GetDefaultItemMetadata(this Project project, string name, bool evaluated, string defaultValue = "")
public static string GetDefaultItemMetadata(this Project project, string name, bool evaluated,
string defaultValue = "")
{
var meta = project.AllEvaluatedItemDefinitionMetadata.LastOrDefault(
m => m.ItemType.Equals("SliceCompile") && m.Name.Equals(name));
Expand Down Expand Up @@ -208,6 +209,13 @@ public static void SetProperty(this Project project, string name, string value,
}
}

public static bool HasProjectFlavor(this Project project, string flavor)
{
var property = project.Xml.Properties.FirstOrDefault(
p => p.Name.Equals("ProjectTypeGuids", StringComparison.CurrentCultureIgnoreCase));
return property != null && property.Value.IndexOf(flavor) != -1;
}

public static void AddProjectFlavorIfNotExists(this Project project, string flavor)
{
var property = project.Xml.Properties.FirstOrDefault(
Expand Down
14 changes: 13 additions & 1 deletion IceBuilder_Common/NuGetI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ public NuGetI()
PackageInstaller = model.GetService<IVsPackageInstaller>();
PackageRestorer = model.GetService<IVsPackageRestorer>();
PackageInstallerEvents = model.GetService<IVsPackageInstallerEvents>();
PackageInstallerEvents.PackageInstalled += PackageInstallerEvents_PackageInstalled;
PackageInstallerEvents.PackageReferenceAdded += PackageInstallerEvents_PackageReferenceAdded;
}

private void PackageInstallerEvents_PackageReferenceAdded(IVsPackageMetadata metadata)
{
ThreadHelper.JoinableTaskFactory.Run(async () =>
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (BatchEnd != null)
{
BatchEnd();
}
});
}

public bool IsPackageInstalled(EnvDTE.Project project, string packageId)
Expand Down
3 changes: 2 additions & 1 deletion IceBuilder_Common/ProjectHelperI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public void UpdateProject(IVsProject project, Action<MSProject> action, bool swi
}

protected static async Task<T>
WithProjectAsync<T>(UnconfiguredProject unconfiguredProject, Func<MSProject, T> func, bool switchToMainThread = false)
WithProjectAsync<T>(UnconfiguredProject unconfiguredProject, Func<MSProject, T> func,
bool switchToMainThread = false)
{
T result = default(T);
var service = unconfiguredProject.ProjectService.Services.ProjectLockService;
Expand Down
Loading

0 comments on commit d8f490b

Please sign in to comment.