Skip to content

Commit

Permalink
[build][project-system] Remove YetiVSI.ProjectSystem hack
Browse files Browse the repository at this point in the history
YetiVSI.ProjectSystem.v15/16/17 exist to workaround the problem of backwards incompatibility in Visual Studio APIs. In order to build a single VSIX that is compatible with both VS2017 and VS2019 (that's where the compatibility is broken), we build two versions of `YetiVSI.ProjectSystem` and then resolve the correct one in runtime. This has a benefit of resolving everything statically in the code and having tests for each version of the API, but it complicates and slows down the build.

Since the incompatibility surface is really small (a single member changed its type), we can just workaround that difference via reflection and remove the whole `YetiVSI.ProjectSystem` machinery.

GitOrigin-RevId: e145900cd7f99c59eaf75ab68ac253fb04620007
  • Loading branch information
werat authored and copybara-github committed Jul 18, 2022
1 parent 00fb81a commit a00a250
Show file tree
Hide file tree
Showing 27 changed files with 46 additions and 521 deletions.
16 changes: 1 addition & 15 deletions YetiVSI.2019/YetiVSI.2019.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -433,19 +433,5 @@
</Content>
</ItemGroup>
<Import Project="..\YetiVSI.Shared\YetiVSI.Shared.projitems" Label="Shared" />
<Target Name="BuildProjectSystemAdapterAssemblies" AfterTargets="MainResourcesGeneration">
<ItemGroup>
<ProjectToBuild Include="..\YetiVSI.ProjectSystem.v15\YetiVSI.ProjectSystem.v15.csproj" />
<ProjectToBuild Include="..\YetiVSI.ProjectSystem.v16\YetiVSI.ProjectSystem.v16.csproj" />
</ItemGroup>
<MSBuild Projects="@(ProjectToBuild)" Properties="Configuration=$(SharedConfiguration)">
<Output TaskParameter="TargetOutputs" ItemName="ProjectSystemAdapterAssemblies" />
</MSBuild>
<ItemGroup>
<EmbeddedResource Include="@(ProjectSystemAdapterAssemblies)">
<LogicalName>Embedded/%(Filename)%(Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Target>
<Import Project="..\YetiVSI.Shared\AdditionalLibSuppression.targets" />
</Project>
</Project>
4 changes: 0 additions & 4 deletions YetiVSI.2022/YetiVSI.2022.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,6 @@
<Project>{1731F5D3-FDF7-4D5B-99FE-910E0924173A}</Project>
<Name>YetiVSI.ProjectSystem.Abstractions</Name>
</ProjectReference>
<ProjectReference Include="..\YetiVSI.ProjectSystem.v17\YetiVSI.ProjectSystem.v17.csproj">
<Project>{590E755F-957E-4D6B-B427-9E37E8A65F01}</Project>
<Name>YetiVSI.ProjectSystem.v17</Name>
</ProjectReference>
</ItemGroup>
<!-- Shared references -->
<ItemGroup>
Expand Down

This file was deleted.

13 changes: 0 additions & 13 deletions YetiVSI.ProjectSystem.Shared/YetiVSI.ProjectSystem.Shared.shproj

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions YetiVSI.ProjectSystem.Tests.v15/.gitignore

This file was deleted.

20 changes: 0 additions & 20 deletions YetiVSI.ProjectSystem.Tests.v15/ConfiguredProjectAdapterTests.cs

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions YetiVSI.ProjectSystem.Tests.v16/.gitignore

This file was deleted.

20 changes: 0 additions & 20 deletions YetiVSI.ProjectSystem.Tests.v16/ConfiguredProjectAdapterTests.cs

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions YetiVSI.ProjectSystem.Tests.v17/.gitignore

This file was deleted.

20 changes: 0 additions & 20 deletions YetiVSI.ProjectSystem.Tests.v17/ConfiguredProjectAdapterTests.cs

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions YetiVSI.ProjectSystem.v15/.gitignore

This file was deleted.

20 changes: 0 additions & 20 deletions YetiVSI.ProjectSystem.v15/YetiVSI.ProjectSystem.v15.csproj

This file was deleted.

2 changes: 0 additions & 2 deletions YetiVSI.ProjectSystem.v16/.gitignore

This file was deleted.

20 changes: 0 additions & 20 deletions YetiVSI.ProjectSystem.v16/YetiVSI.ProjectSystem.v16.csproj

This file was deleted.

2 changes: 0 additions & 2 deletions YetiVSI.ProjectSystem.v17/.gitignore

This file was deleted.

20 changes: 0 additions & 20 deletions YetiVSI.ProjectSystem.v17/YetiVSI.ProjectSystem.v17.csproj

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using Microsoft.VisualStudio.ProjectSystem.Properties;
using YetiVSI.ProjectSystem.Abstractions;

namespace YetiVSI.ProjectSystem
namespace YetiVSI
{
public class ConfiguredProjectAdapter : IAsyncProject
{
Expand All @@ -29,11 +29,34 @@ public class ConfiguredProjectAdapter : IAsyncProject

public ConfiguredProjectAdapter(ConfiguredProject configuredProject)
{
// UnconfiguredProject is the same in VS2017 and VS2019.
unconfiguredProject = configuredProject.UnconfiguredProject;

#if VS2019
// Services is an interface in VS2017 and an abstract class in VS2019.
// Use reflection to bypass this difference, the rest of the fields are the same.
var servicesProperty = configuredProject.GetType().GetProperty("Services");
var services = servicesProperty.GetValue(configuredProject, null);

// Get to UserPropertiesProvider.GetCommonProperties().
var uppProperty = services.GetType().GetProperty("UserPropertiesProvider");
var upp = (IProjectPropertiesProvider)uppProperty.GetValue(services);
userProperties = upp.GetCommonProperties();

// Get to ProjectPropertiesProvider.GetCommonProperties().
var pppProperty = services.GetType().GetProperty("ProjectPropertiesProvider");
var ppp = (IProjectPropertiesProvider)pppProperty.GetValue(services);
projectProperties = ppp.GetCommonProperties();

#elif VS2022
userProperties =
configuredProject.Services.UserPropertiesProvider.GetCommonProperties();
projectProperties =
configuredProject.Services.ProjectPropertiesProvider.GetCommonProperties();

#else
#error Unsupported Visual Studio version
#endif
}

public Task<string> GetAbsoluteRootPathAsync()
Expand Down
Loading

0 comments on commit a00a250

Please sign in to comment.