Skip to content

Commit

Permalink
Viewer: Add portable-exe with embedded dlls
Browse files Browse the repository at this point in the history
  • Loading branch information
jonthysell committed Oct 9, 2018
1 parent 8834b56 commit 951e31d
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Mzinga.Engine/Mzinga.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
<Import Project="..\Mzinga.Shared\Mzinga.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy $(TargetDir)$(TargetName).exe $(SolutionDir)Mzinga.Viewer\$(OutDir)
copy $(TargetDir)$(TargetName).pdb $(SolutionDir)Mzinga.Viewer\$(OutDir)</PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
54 changes: 54 additions & 0 deletions Mzinga.Viewer/Mzinga.Viewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,46 @@
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug %28Portable%29|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug %28Portable%29\</OutputPath>
<DefineConstants>TRACE;DEBUG;WINDOWS_WPF;PORTABLE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug %28Portable%29|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug %28Portable%29\</OutputPath>
<DefineConstants>TRACE;DEBUG;WINDOWS_WPF</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release %28Portable%29|AnyCPU'">
<OutputPath>bin\Release %28Portable%29\</OutputPath>
<DefineConstants>TRACE;WINDOWS_WPF;PORTABLE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release %28Portable%29|x86'">
<OutputPath>bin\x86\Release %28Portable%29\</OutputPath>
<DefineConstants>TRACE;WINDOWS_WPF</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommonServiceLocator, Version=2.0.4.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.2.0.4\lib\net46\CommonServiceLocator.dll</HintPath>
Expand Down Expand Up @@ -203,12 +243,26 @@
<ItemGroup>
<Resource Include="Resources\gameoversfx.wav" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mzinga.Engine\Mzinga.Engine.csproj">
<Project>{6273e30d-eaaa-42f3-bcdc-3ad28aeed433}</Project>
<Name>Mzinga.Engine</Name>
<Aliases>MEDONTUSE</Aliases>
</ProjectReference>
</ItemGroup>
<Import Project="..\Mzinga.Shared\Mzinga.Shared.projitems" Label="Shared" />
<Import Project="..\Mzinga.SharedUX\Mzinga.SharedUX.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>copy /y "$(SolutionDir)README.md" "$(TargetDir)Readme.txt" &amp;&amp; copy /y "$(SolutionDir)LICENSE.md" "$(TargetDir)License.txt" &amp;&amp; copy /y "$(SolutionDir)External\MVVMLight\LICENSE.md" "$(TargetDir)MVVM Light License.txt"</PreBuildEvent>
</PropertyGroup>
<Target Name="AfterResolveReferences">
<ItemGroup Condition="'$(Configuration)' == 'Debug (Portable)' Or '$(Configuration)' == 'Release (Portable)'">
<EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'">
<LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
35 changes: 35 additions & 0 deletions Mzinga.Viewer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
// THE SOFTWARE.

using System;
using System.IO;
using System.Globalization;
using System.Reflection;
using System.Windows;

namespace Mzinga.Viewer
Expand All @@ -38,6 +41,11 @@ public static void Main(string[] args)
{
try
{
#if PORTABLE
// Hook into assembly resolution since the assemblies are embedded
AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
#endif

if (null != args && args.Length > 0)
{
configFile = args[0];
Expand All @@ -53,5 +61,32 @@ public static void Main(string[] args)
MessageBox.Show(message, "Unhandled Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

#if PORTABLE
// Adapted from http://www.digitallycreated.net/Blog/61/combining-multiple-assemblies-into-a-single-exe-for-a-wpf-application
private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
AssemblyName assemblyName = new AssemblyName(args.Name);

string path = assemblyName.Name + ".dll";
if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false)
{
path = string.Format(@"{0}\{1}", assemblyName.CultureInfo, path);
}

using (Stream stream = executingAssembly.GetManifestResourceStream(path))
{
if (null == stream)
{
return null;
}

byte[] assemblyRawBytes = new byte[stream.Length];
stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
return Assembly.Load(assemblyRawBytes);
}
}
#endif
}
}
52 changes: 52 additions & 0 deletions Mzinga.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,59 +37,111 @@ Global
Mzinga.Shared\Mzinga.Shared.projitems*{ab491ff7-2645-4df0-af16-ee5ad7222a35}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug (Portable)|Any CPU = Debug (Portable)|Any CPU
Debug (Portable)|Mixed Platforms = Debug (Portable)|Mixed Platforms
Debug (Portable)|x86 = Debug (Portable)|x86
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x86 = Debug|x86
Release (Portable)|Any CPU = Release (Portable)|Any CPU
Release (Portable)|Mixed Platforms = Release (Portable)|Mixed Platforms
Release (Portable)|x86 = Release (Portable)|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Debug (Portable)|Any CPU.ActiveCfg = Debug (Portable)|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Debug (Portable)|Any CPU.Build.0 = Debug (Portable)|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Debug (Portable)|Mixed Platforms.ActiveCfg = Debug (Portable)|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Debug (Portable)|Mixed Platforms.Build.0 = Debug (Portable)|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Debug (Portable)|x86.ActiveCfg = Debug|x86
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Debug|x86.ActiveCfg = Debug|x86
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Release (Portable)|Any CPU.ActiveCfg = Release (Portable)|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Release (Portable)|Any CPU.Build.0 = Release (Portable)|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Release (Portable)|Mixed Platforms.ActiveCfg = Release (Portable)|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Release (Portable)|Mixed Platforms.Build.0 = Release (Portable)|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Release (Portable)|x86.ActiveCfg = Release|x86
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Release|Any CPU.Build.0 = Release|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{AB491FF7-2645-4DF0-AF16-EE5AD7222A35}.Release|x86.ActiveCfg = Release|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Debug (Portable)|Any CPU.ActiveCfg = Debug|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Debug (Portable)|Mixed Platforms.ActiveCfg = Debug|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Debug (Portable)|x86.ActiveCfg = Debug|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Debug|Any CPU.ActiveCfg = Debug|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Debug|Any CPU.Build.0 = Debug|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Debug|Mixed Platforms.Build.0 = Debug|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Debug|x86.ActiveCfg = Debug|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Release (Portable)|Any CPU.ActiveCfg = Release|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Release (Portable)|Mixed Platforms.ActiveCfg = Release|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Release (Portable)|x86.ActiveCfg = Release|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Release|Any CPU.ActiveCfg = Release|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Release|Any CPU.Build.0 = Release|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Release|Mixed Platforms.ActiveCfg = Release|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Release|Mixed Platforms.Build.0 = Release|x86
{EB905695-D35D-4B73-AE9C-DDFF734604F8}.Release|x86.ActiveCfg = Release|x86
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Debug (Portable)|Any CPU.ActiveCfg = Debug|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Debug (Portable)|Any CPU.Build.0 = Debug|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Debug (Portable)|Mixed Platforms.ActiveCfg = Debug|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Debug (Portable)|Mixed Platforms.Build.0 = Debug|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Debug (Portable)|x86.ActiveCfg = Debug|x86
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Debug|x86.ActiveCfg = Debug|x86
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Release (Portable)|Any CPU.ActiveCfg = Release|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Release (Portable)|Any CPU.Build.0 = Release|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Release (Portable)|Mixed Platforms.ActiveCfg = Release|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Release (Portable)|Mixed Platforms.Build.0 = Release|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Release (Portable)|x86.ActiveCfg = Release|x86
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Release|Any CPU.Build.0 = Release|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{9824E8FD-6155-4C02-A3A4-5D39355F01FE}.Release|x86.ActiveCfg = Release|x86
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Debug (Portable)|Any CPU.ActiveCfg = Debug|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Debug (Portable)|Any CPU.Build.0 = Debug|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Debug (Portable)|Mixed Platforms.ActiveCfg = Debug|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Debug (Portable)|Mixed Platforms.Build.0 = Debug|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Debug (Portable)|x86.ActiveCfg = Debug|x86
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Debug|x86.ActiveCfg = Debug|x86
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Release (Portable)|Any CPU.ActiveCfg = Release|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Release (Portable)|Any CPU.Build.0 = Release|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Release (Portable)|Mixed Platforms.ActiveCfg = Release|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Release (Portable)|Mixed Platforms.Build.0 = Release|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Release (Portable)|x86.ActiveCfg = Release|x86
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Release|Any CPU.Build.0 = Release|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6273E30D-EAAA-42F3-BCDC-3AD28AEED433}.Release|x86.ActiveCfg = Release|x86
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Debug (Portable)|Any CPU.ActiveCfg = Debug|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Debug (Portable)|Any CPU.Build.0 = Debug|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Debug (Portable)|Mixed Platforms.ActiveCfg = Debug|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Debug (Portable)|Mixed Platforms.Build.0 = Debug|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Debug (Portable)|x86.ActiveCfg = Debug|x86
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Debug|x86.ActiveCfg = Debug|x86
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Release (Portable)|Any CPU.ActiveCfg = Release|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Release (Portable)|Any CPU.Build.0 = Release|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Release (Portable)|Mixed Platforms.ActiveCfg = Release|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Release (Portable)|Mixed Platforms.Build.0 = Release|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Release (Portable)|x86.ActiveCfg = Release|x86
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Release|Any CPU.Build.0 = Release|Any CPU
{B9817AC4-3097-4A72-9A50-D9F56D47AF2C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
Expand Down

0 comments on commit 951e31d

Please sign in to comment.