Skip to content

Commit 20f2dac

Browse files
committedNov 17, 2021
Embed EnvDTE
1 parent 9b64125 commit 20f2dac

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed
 

‎src/VsixTesting/Vs/VisualStudioUtil.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ internal static partial class VisualStudioUtil
2323

2424
public static DTE GetDTE(Process process)
2525
{
26-
string namePattern = $@"!VisualStudio\.DTE\.(\d+\.\d+):{process.Id.ToString()}";
27-
return (DTE)RunningObjectTable.GetRunningObjects(namePattern).FirstOrDefault();
26+
return (DTE)GetDTEObject(process);
2827
}
2928

3029
public static async Task<DTE> GetDTE(Process process, TimeSpan timeout)
@@ -164,6 +163,12 @@ internal static bool IsValidInstallationDirectory(string installationPath)
164163
internal static string GetApplicationPath(string installationPath)
165164
=> Path.Combine(installationPath, "Common7", "IDE", ProcessName + ".exe");
166165

166+
internal static object GetDTEObject(Process process)
167+
{
168+
string namePattern = $@"!VisualStudio\.DTE\.(\d+\.\d+):{process.Id.ToString()}";
169+
return RunningObjectTable.GetRunningObjects(namePattern).FirstOrDefault();
170+
}
171+
167172
private static string GetRootSuffixAsArgument(string rootSuffix)
168173
=> string.IsNullOrWhiteSpace(rootSuffix) ? string.Empty : $"/rootSuffix {rootSuffix}";
169174
}

‎src/VsixTesting/VsixTesting.csproj

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
</ItemGroup>
2222

2323
<ItemGroup>
24+
<Reference Include="Microsoft.CSharp" />
2425
<Reference Include="PresentationFramework" />
2526
<Reference Include="System.Runtime.Remoting" />
2627
<Reference Include="WindowsBase" />
@@ -31,4 +32,12 @@
3132
<PackageReference Include="Microsoft.VisualStudio.SDK.EmbedInteropTypes" Version="15.0.17" PrivateAssets="all" />
3233
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta-63127-02" PrivateAssets="All" />
3334
</ItemGroup>
35+
36+
<Target Name="EmbedEnvDTE" AfterTargets="ResolveReferences" BeforeTargets="FindReferenceAssembliesForReferences">
37+
<ItemGroup>
38+
<ReferencePath Condition="'%(FileName)' == 'EnvDTE'">
39+
<EmbedInteropTypes>true</EmbedInteropTypes>
40+
</ReferencePath>
41+
</ItemGroup>
42+
</Target>
3443
</Project>

‎test/VsixTesting.Xunit.Tests/VsFactTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void FactWorks()
2626

2727
[VsFact]
2828
void FactRunningInsideVisualStudio()
29-
=> Assert.NotNull(VisualStudioUtil.GetDTE(Process.GetCurrentProcess()));
29+
=> Assert.NotNull(VisualStudioUtil.GetDTEObject(Process.GetCurrentProcess()));
3030

3131
[VsFact(Skip = "Fact Skip works.")]
3232
void FactSkipWorks()

‎test/VsixTesting.Xunit.Tests/VsTheoryTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void TheoryWorks(int number)
3333
[InlineData(0)]
3434
void TheoryRunningInsideVisualStudio(int zero)
3535
{
36-
Assert.NotNull(VisualStudioUtil.GetDTE(Process.GetCurrentProcess()));
36+
Assert.NotNull(VisualStudioUtil.GetDTEObject(Process.GetCurrentProcess()));
3737
Assert.Equal(0, zero);
3838
}
3939

0 commit comments

Comments
 (0)
Please sign in to comment.