یکی کردن اسمبلیهای یک پروژهی WPF
نویسنده: وحید نصیری
تاریخ: ۱۳۹۲/۱۰/۳۰ ۱۸:۳۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
namespace MergeAssembliesIntoWPF.ViewModels
{
public class ViewModel1
{
public string Data { set; get; }
public ViewModel1()
{
Data = "Test";
}
}
} <UserControl x:Class="MergeAssembliesIntoWPF.Shell.View1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:VM="clr-namespace:MergeAssembliesIntoWPF.ViewModels;assembly=MergeAssembliesIntoWPF.ViewModels"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<VM:ViewModel1 x:Key="ViewModel1" />
</UserControl.Resources>
<Grid DataContext="{Binding Source={StaticResource ViewModel1}}">
<TextBlock Text="{Binding Data}" />
</Grid>
</UserControl> <Window x:Class="MergeAssembliesIntoWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:V="clr-namespace:MergeAssembliesIntoWPF.Shell;assembly=MergeAssembliesIntoWPF.Shell"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<V:View1 x:Key="View1" />
</Window.Resources>
<Grid>
<V:View1 />
</Grid>
</Window> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterResolveReferences">
<ItemGroup>
<EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'">
<LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
</Target>
using System;
using System.Globalization;
using System.Reflection;
namespace MergeAssembliesIntoWPF
{
public class Program
{
[STAThreadAttribute]
public static void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
App.Main();
}
private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
{
var executingAssembly = Assembly.GetExecutingAssembly();
var assemblyName = new AssemblyName(args.Name);
var path = assemblyName.Name + ".dll";
if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false)
{
path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path);
}
using (var stream = executingAssembly.GetManifestResourceStream(path))
{
if (stream == null)
return null;
var assemblyRawBytes = new byte[stream.Length];
stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
return Assembly.Load(assemblyRawBytes);
}
}
}
}
بررسی لاگ Application ویندوز خبر از پیدا نشدن فایلی (System.IO.Exception) در متد Main میدهد و نکته دیگری در آن ذکر نشده.
آیا راه حلی وجود دارد؟
private static Assembly loadEmbeddedAssembly(string name)
{
if (name.EndsWith("Retargetable=Yes")) {
return Assembly.Load(new AssemblyName(name));
}
// Rest of your code
//...
} [MethodImpl(MethodImplOptions.NoOptimization)]
PM> Install-Package Costura.Fody
The type or namespace name 'Stimulsoft' could not be found (are you missing a using directive or an assembly reference?)
چرا برای اسمبلیهای تلریک چنین مشکلی به وجود نمیآید و اینکه علاوه بر اسمبلیهای زیپ شده خود اسمبلیها نیز در فایل قرار داده شد؟
<Weavers> <Costura CreateTemporaryAssemblies='true' /> </Weavers>