Skip to content
This repository was archived by the owner on Jul 2, 2022. It is now read-only.

Commit 197bc52

Browse files
committed
Unify package versions, add MEF test and composition diagnostics
All packages are now versioned the same. When composition fails, leveraging Microsoft.ComponentModel.Composition.Diagnostics.dll we can generate a log file that can be used to inspect the failure.
1 parent 0ce7ce3 commit 197bc52

File tree

15 files changed

+98
-84
lines changed

15 files changed

+98
-84
lines changed

build.proj

+46-71
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66
<IntermediateOutputPath>.nuget\</IntermediateOutputPath>
77
<PackagesPath>$(IntermediateOutputPath)packages</PackagesPath>
88
<Out Condition=" '$(Out)' == '' ">$(MSBuildThisFileDirectory)out</Out>
9-
<!--
10-
<SkipReadGitCache Condition=" '$(SkipReadGitCache)' == '' ">true</SkipReadGitCache>
11-
<SkipWriteGitCache Condition=" '$(SkipWriteGitCache)' == '' ">true</SkipWriteGitCache>
12-
-->
139
<!-- We always use DeployExtension=false from the build script to ensure a clean build, but
1410
also because if we run integration tests, we do so by installing the resulting VSIX,
1511
which makes for a cleaner test too. -->
16-
<CommonBuildProperties>WarningLevel=0;NoWarn=1591;RunCodeAnalysis=false;Configuration=$(Configuration);Out=$(Out);SkipReadGitCache=$(SkipReadGitCache);SkipWriteGitCache=$(SkipWriteGitCache);DeployExtension=false</CommonBuildProperties>
17-
<DefaultImportance Condition=" '$(DefaultImportance)' == '' ">normal</DefaultImportance>
12+
<CommonBuildProperties>WarningLevel=0;NoWarn=1591;RunCodeAnalysis=false;Configuration=$(Configuration);Out=$(Out);DeployExtension=false</CommonBuildProperties>
13+
<DefaultImportance Condition=" '$(DefaultImportance)' == '' ">high</DefaultImportance>
1814
</PropertyGroup>
1915

2016
<!-- Integration-test related stuff -->
@@ -27,14 +23,15 @@
2723
</PropertyGroup>
2824

2925
<PropertyGroup Condition=" '$(IntegrationTest)' == 'true' ">
26+
<TestVsVersions>$([MSBuild]::ValueOrDefault('$(VisualStudioVersions)', 'All'))</TestVsVersions>
3027
<!-- When running integration tests, either use an explicit VisualStudioVersion received or fallback to All -->
31-
<CommonBuildProperties>$(CommonBuildProperties);VisualStudioVersions=$([MSBuild]::ValueOrDefault('$(VisualStudioVersions)', 'All'))</CommonBuildProperties>
28+
<CommonBuildProperties>$(CommonBuildProperties);VisualStudioVersions=$(TestVsVersions)</CommonBuildProperties>
3229
</PropertyGroup>
3330

3431
<ItemGroup>
3532
<Solution Include="src\*.sln"/>
3633
<TestProject Include="src\**\*.Tests.csproj" />
37-
<TestProject Include="src\**\*.IntegrationTests.csproj" Condition=" '$(IntegrationTest)' == 'true' " />
34+
<IntegrationTestProject Include="src\**\*.IntegrationTests.csproj" />
3835
</ItemGroup>
3936

4037
<Target Name="All" DependsOnTargets="Build;Test;Package" />
@@ -54,12 +51,11 @@
5451
<MSBuild Projects="@(Solution)" Properties="$(CommonBuildProperties)" />
5552

5653
<ItemGroup>
57-
<CandidateNuSpec Include="src\**\*.nuspec" />
58-
<NuSpec Include="@(CandidateNuSpec)" Condition=" '%(Filename)' != 'Merq' And '%(Filename)' != 'Merq.Installer' " />
54+
<NuSpec Include="src\**\*.nuspec" />
5955
</ItemGroup>
6056
</Target>
6157

62-
<Target Name="Package" DependsOnTargets="BuildInstaller;BuildPackages;FindPackages;DeletePackages;PrepareMetaPackage;BuildMetaPackage" />
58+
<Target Name="Package" DependsOnTargets="BuildInstaller;BuildPackages;FindPackages;DeletePackages" />
6359

6460
<Target Name="BuildInstaller">
6561
<!-- Refresh the VSIX with the SystemComponent flag now for redistribution -->
@@ -146,69 +142,12 @@
146142
<Delete Files="%(NuPackage.FullPath)" Condition=" '$(ExitCode)' == '0' Or '$(ExitCode)' == '18' " />
147143
</Target>
148144

149-
<Target Name="PrepareMetaPackage" DependsOnTargets="DeletePackages">
150-
<ItemGroup>
151-
<EventsPackage Include="@(NuPackage)" Condition=" '%(Id)' == 'Merq.Events' And Exists('%(FullPath)') " />
152-
<CommandsPackage Include="@(NuPackage)" Condition=" '%(Id)' == 'Merq.Commands' And Exists('%(FullPath)') " />
153-
</ItemGroup>
154-
<PropertyGroup>
155-
<EventsVersion>@(EventsPackage -> '%(Version)%(ReleaseLabel)')</EventsVersion>
156-
<CommandsVersion>@(CommandsPackage -> '%(Version)%(ReleaseLabel)')</CommandsVersion>
157-
</PropertyGroup>
158-
</Target>
159-
160-
<Target Name="BuildMetaPackage" DependsOnTargets="PrepareMetaPackage" Condition=" '$(EventsVersion)' != '' Or '$(CommandsVersion)' != '' ">
161-
<!-- There is at least a new Events or Commands package -->
162-
<Exec Command="$(Curl) -s -0 https://api.nuget.org/v3/registration1/merq.events/index.json" StandardOutputImportance="low" ConsoleToMSBuild="true">
163-
<Output TaskParameter="ConsoleOutput" PropertyName="JsonContent" />
164-
</Exec>
165-
<JsonPeek JsonContent="$(JsonContent)" JPath="items[0].upper">
166-
<Output TaskParameter="Result" PropertyName="PublishedEvents" />
167-
</JsonPeek>
168-
169-
<Exec Command="$(Curl) -s -0 https://api.nuget.org/v3/registration1/merq.commands/index.json" StandardOutputImportance="low" ConsoleToMSBuild="true">
170-
<Output TaskParameter="ConsoleOutput" PropertyName="JsonContent" />
171-
</Exec>
172-
<JsonPeek JsonContent="$(JsonContent)" JPath="items[0].upper">
173-
<Output TaskParameter="Result" PropertyName="PublishedCommands" />
174-
</JsonPeek>
175-
176-
<XmlPeek XmlInputPath="src\Merq.nuspec" Query="/package/metadata/version/text()">
177-
<Output TaskParameter="Result" PropertyName="BaseVersion" />
178-
</XmlPeek>
179-
180-
<Exec Command="$(Curl) -s -0 https://api.nuget.org/v3/registration1/merq/index.json" StandardOutputImportance="low" ConsoleToMSBuild="true">
181-
<Output TaskParameter="ConsoleOutput" PropertyName="JsonContent" />
182-
</Exec>
183-
<JsonPeek JsonContent="$(JsonContent)" JPath="items[0].upper">
184-
<Output TaskParameter="Result" PropertyName="PublishedMeta" />
185-
</JsonPeek>
186-
187-
<CalculateMetaVersion BaseVersion="$(BaseVersion)" PublishedVersion="$(PublishedMeta)">
188-
<Output TaskParameter="TargetVersion" PropertyName="TargetVersion" />
189-
</CalculateMetaVersion>
190-
191-
<PropertyGroup>
192-
<EventsVersion Condition=" '$(EventsVersion)' == '' ">$(PublishedEvents)</EventsVersion>
193-
<CommandsVersion Condition=" '$(CommandsVersion)' == '' ">$(PublishedCommands)</CommandsVersion>
194-
</PropertyGroup>
195-
196-
<Message Text="Determined new meta package version $(TargetVersion) with dependencies:
197-
Events: $(EventsVersion) (currently published version is $(PublishedEvents))
198-
Commands: $(CommandsVersion) (currently published version is $(PublishedCommands))"
199-
Importance="high" />
200-
201-
<Exec Command='"$(NuGet)" Pack src\Merq.nuspec -Version $(TargetVersion) -Properties events=$(EventsVersion);commands=$(CommandsVersion) -OutputDirectory $(Out)' />
202-
</Target>
203-
204145
<Import Project="$(PackagesPath)\MSBuilder.CodeTaskAssembly\build\MSBuilder.CodeTaskAssembly.props"
205146
Condition=" Exists('$(PackagesPath)\MSBuilder.CodeTaskAssembly\build\MSBuilder.CodeTaskAssembly.props') " />
206147
<Import Project="$(PackagesPath)\MSBuilder.DumpItems\build\MSBuilder.DumpItems.targets"
207148
Condition=" Exists('$(PackagesPath)\MSBuilder.DumpItems\build\MSBuilder.DumpItems.targets') "/>
208149
<Import Project="$(PackagesPath)\MSBuilder.IsAdministrator\build\MSBuilder.IsAdministrator.targets"
209150
Condition=" Exists('$(PackagesPath)\MSBuilder.IsAdministrator\build\MSBuilder.IsAdministrator.targets') "/>
210-
<Import Project="$(PackagesPath)\JsonPoke.MSBuild\build\JsonPoke.MSBuild.Targets"
211-
Condition=" Exists('$(PackagesPath)\JsonPoke.MSBuild\build\JsonPoke.MSBuild.Targets') "/>
212151
<Import Project="$(PackagesPath)\Microsoft.VSSDK.BuildTools\build\Microsoft.VSSDK.BuildTools.targets"
213152
Condition=" Exists('$(PackagesPath)\Microsoft.VSSDK.BuildTools\build\Microsoft.VSSDK.BuildTools.targets') And '$(IntegrationTest)' == 'true' " />
214153
<Import Project="$(PackagesPath)\MSBuilder.VsixInstaller\build\MSBuilder.VsixInstaller.targets"
@@ -229,13 +168,20 @@
229168
<Target Name="Test" DependsOnTargets="$(TestDependsOn)" />
230169

231170
<Target Name="PrepareInstall" DependsOnTargets="IsAdministrator">
232-
<ItemGroup>
171+
<ItemGroup Condition=" '$(TestVsVersions)' == 'All' ">
233172
<SupportedVersion Include="11.0;12.0;14.0" />
173+
</ItemGroup>
174+
<ItemGroup Condition=" '$(TestVsVersions)' != 'All' ">
175+
<SupportedVersion Include="11.0" Condition=" $(TestVsVersions.Contains('11.0')) == 'true' " />
176+
<SupportedVersion Include="12.0" Condition=" $(TestVsVersions.Contains('12.0')) == 'true' " />
177+
<SupportedVersion Include="14.0" Condition=" $(TestVsVersions.Contains('14.0')) == 'true' " />
178+
</ItemGroup>
179+
<ItemGroup>
234180
<SupportedVersion>
235-
<VsixInstaller>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\%(Identity)', 'InstallDir', null, RegistryView.Registry32))VSIXInstaller.exe</VsixInstaller>
181+
<DevEnv>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\%(Identity)', 'InstallDir', null, RegistryView.Registry32))devenv.exe</DevEnv>
236182
</SupportedVersion>
237183
<InstalledVersion Include="@(SupportedVersion)"
238-
Condition=" Exists('%(VsixInstaller)') " />
184+
Condition=" Exists('%(DevEnv)') " />
239185
</ItemGroup>
240186

241187
<Message Importance="$(DefaultImportance)" Text="Found installed Visual Studio versions @(InstalledVersion)." />
@@ -253,6 +199,25 @@
253199
<EnabledExtension Include="@(_EnabledExtension)" Condition=" '$(IsAdministrator)' == 'False' And '%(InstalledPerMachine)' == 'False' And '%(SystemComponent)' == 'False' " />
254200
</ItemGroup>
255201

202+
<PropertyGroup>
203+
<PS>%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</PS>
204+
</PropertyGroup>
205+
206+
<!-- Existing versions of Xamarin will collide with the provided IAsyncManager export, even from the normal hive -->
207+
<!-- NOTE: we could check the product version too if needed: Version is available from the Win32_Product structure -->
208+
<Exec Command="&quot;$(PS)&quot; -NoProfile -Command &quot;&amp; { get-wmiobject Win32_Product | Where-Object Name -eq Xamarin | Select-Object -ExpandProperty IdentifyingNumber }&quot;"
209+
ConsoleToMSBuild="true">
210+
<Output TaskParameter="ConsoleOutput" PropertyName="XamarinProductCode" />
211+
</Exec>
212+
213+
<!-- TODO: eventually we will need to do this for the normal hive Merq installation itself instead :(
214+
although if that comes as a VSIX, it may be simpler to achieve?
215+
-->
216+
<Error Condition=" '$(IsAdministrator)' == 'false' And '$(XamarinProductCode)' != '' "
217+
Text="Existing Xamarin product installation found, but current user is not Administrator and can't uninstall it." />
218+
219+
<Exec Command='msiexec /x $(XamarinProductCode) /norestart /q | more'
220+
Condition=" '$(XamarinProductCode)' != '' " />
256221
</Target>
257222

258223
<Target Name="DisableExtensions">
@@ -297,9 +262,14 @@
297262
<MSBuild Projects="@(TestProject)" BuildInParallel="false" Targets="GetTargetPath" Properties="$(CommonBuildProperties)">
298263
<Output TaskParameter="TargetOutputs" ItemName="_TestAssembly" />
299264
</MSBuild>
265+
<MSBuild Projects="@(IntegrationTestProject)" BuildInParallel="false" Targets="GetTargetPath" Properties="$(CommonBuildProperties)"
266+
Condition=" '@(IntegrationTestProject)' != '' ">
267+
<Output TaskParameter="TargetOutputs" ItemName="_IntegrationTestAssembly" />
268+
</MSBuild>
300269

301270
<ItemGroup>
302271
<TestAssembly Include="@(_TestAssembly)" Condition=" Exists('%(_TestAssembly.FullPath)') " />
272+
<IntegrationTestAssembly Include="@(_IntegrationTestAssembly)" Condition=" Exists('%(_IntegrationTestAssembly.FullPath)') " />
303273
</ItemGroup>
304274

305275
<MakeDir Directories="$(Out)" Condition="!Exists('$(Out)')" />
@@ -317,6 +287,11 @@
317287
<Exec Command="$(CoverageConsole) $(CoverageOptions) -target:$(XunitConsole) -targetargs:&quot;@(TestAssembly, ' ') $(XunitOptions)&quot;"
318288
ConsoleToMSBuild="true"
319289
ContinueOnError="ErrorAndContinue" />
290+
291+
<Exec Command="$(XunitConsole) @(IntegrationTestAssembly, ' ') $(XunitOptions.Replace('test', 'integrationtest'))"
292+
Condition=" '@(IntegrationTestAssembly)' != '' "
293+
ConsoleToMSBuild="true"
294+
ContinueOnError="ErrorAndContinue" />
320295
</Target>
321296

322297
<Target Name="TestMac" DependsOnTargets="PrepareTest" Condition=" '$(OS)' != 'Windows_NT' ">
Binary file not shown.

src/Async/Merq.Async.AsyncManager/GitInfo.txt

-1
This file was deleted.

src/Async/Merq.Async.TaskScheduler/GitInfo.txt

-1
This file was deleted.

src/Async/Merq.Async/GitInfo.txt

-1
This file was deleted.

src/Commands/Merq.Commands.CommandBus/GitInfo.txt

-1
This file was deleted.

src/Commands/Merq.Commands/GitInfo.txt

-1
This file was deleted.

src/Events/Merq.Events.EventStream/GitInfo.txt

-1
This file was deleted.

src/Events/Merq.Events/GitInfo.txt

-1
This file was deleted.

src/GitInfo.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.0-pre
1+
1.0.10-pre

src/Merq.nuspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>Merq</id>
5-
<version>1.0.0-pre</version>
5+
<version>$version$</version>
66
<title>Merq: Command Bus + Event Stream</title>
77
<authors>Mobile Essentials</authors>
88
<owners>mobessen</owners>
@@ -14,8 +14,8 @@
1414
<description>Merq = Command Bus + Event Stream</description>
1515
<copyright>Copyright 2016 © Mobile Essentials</copyright>
1616
<dependencies>
17-
<dependency id="Merq.Commands" version="$commands$" />
18-
<dependency id="Merq.Events" version="$events$" />
17+
<dependency id="Merq.Commands" version="$version$" />
18+
<dependency id="Merq.Events" version="$version$" />
1919
</dependencies>
2020
</metadata>
2121
<files>

src/Merq.props

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
<RestorePackages>false</RestorePackages>
2323
<Out Condition=" '$(Out)' == '' ">$(OutputPath)</Out>
2424
<ProjectNuSpec>$([System.IO.Path]::ChangeExtension($(MSBuildProjectFullPath), '.nuspec'))</ProjectNuSpec>
25-
<GitInfoReportImportance>high</GitInfoReportImportance>
2625
</PropertyGroup>
2726
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2827
<Optimize>false</Optimize>

src/Vsix/Merq.Vsix.IntegrationTests/ComponentsSpec.cs

+43
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,55 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.Composition;
4+
using System.Diagnostics;
5+
using System.IO;
6+
using System.Linq;
27
using System.Threading.Tasks;
8+
using Microsoft.ComponentModel.Composition.Diagnostics;
39
using Microsoft.VisualStudio.ComponentModelHost;
410
using Xunit;
11+
using Xunit.Abstractions;
512

613
namespace Merq
714
{
815
public class ComponentsSpec
916
{
17+
ITestOutputHelper output;
18+
19+
public ComponentsSpec(ITestOutputHelper output)
20+
{
21+
this.output = output;
22+
}
23+
24+
[InlineData(typeof(IAsyncManager))]
25+
[InlineData(typeof(ICommandBus))]
26+
[InlineData(typeof(IEventStream))]
27+
[VsixTheory]
28+
public void when_retrieving_exports_then_reports_duplicate_services(Type serviceType)
29+
{
30+
var componentModel = GlobalServices.GetService<SComponentModel, IComponentModel>();
31+
var contractName = AttributedModelServices.GetContractName(serviceType);
32+
var components = componentModel.DefaultExportProvider
33+
.GetExports<object, IDictionary<string, object>>(contractName)
34+
.ToArray();
35+
36+
if (components.Length != 1)
37+
{
38+
var info = new CompositionInfo(componentModel.DefaultCatalog, componentModel.DefaultExportProvider);
39+
var log = Path.GetTempFileName();
40+
using (var writer = new StreamWriter(log))
41+
{
42+
CompositionInfoTextFormatter.Write(info, writer);
43+
writer.Flush();
44+
}
45+
46+
output.WriteLine(log);
47+
// Process.Start(new ProcessStartInfo("notepad", log) { UseShellExecute = true });
48+
49+
Assert.False(true, $"Expected only one component of {serviceType.Name}. Composition log at {log}");
50+
}
51+
}
52+
1053
[VsixFact]
1154
public void when_subscribing_and_pushing_events_then_succeeds()
1255
{

src/Vsix/Merq.Vsix.IntegrationTests/Merq.Vsix.IntegrationTests.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
<DocumentationFile />
1818
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
1919
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
20+
<Optimize>false</Optimize>
21+
<DefineConstants>DEBUG;$(DefineConstants)</DefineConstants>
2022
</PropertyGroup>
2123
<ItemGroup>
24+
<Reference Include="Microsoft.ComponentModel.Composition.Diagnostics">
25+
<HintPath>..\..\..\lib\Microsoft.ComponentModel.Composition.Diagnostics.dll</HintPath>
26+
</Reference>
2227
<Reference Include="System" />
2328
<Reference Include="System.Core" />
2429
<Reference Include="Microsoft.CSharp" />

src/Vsix/Merq.Vsix/Merq.Vsix.BindingRedirects.targets

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
<Target Name="CollectBindingRedirected" DependsOnTargets="ResolveAssemblyReferences">
5151
<ItemGroup>
5252
<BindingRedirected Include="@(ReferencePath)" Condition="$([System.String]::new('%(FusionName)').StartsWith('Merq'))" />
53-
<BindingRedirected Include="@(ReferencePath)" Condition="$([System.String]::new('%(FusionName)').StartsWith('Merq'))" />
5453
</ItemGroup>
5554
</Target>
5655

0 commit comments

Comments
 (0)