我们希望将几个项目的解决方案升级到.NET 4.5。我们已经使用Visual Studio 2012.我们使用ILMerge将程序集合并到单个EXE。
我们当前的主项目.csproj文件如下所示:
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release' ">
<CreateItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)'=='.dll'">
<Output ItemName="AssembliesToMerge" TaskParameter="Include" />
</CreateItem>
<PropertyGroup>
<ReferenceAssemblies>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0</ReferenceAssemblies>
</PropertyGroup>
<Message Importance="high" Text="Executing ILMerge...with target platform from $(ReferenceAssemblies)" />
<Exec Command=""$(SolutionDir)LIB\ILMerge.exe" /out:@(MainAssembly) /internalize /targetplatform:v4,"$(ReferenceAssemblies)" "@(IntermediateAssembly)" @(AssembliesToMerge->'"%(FullPath)"', ' ')" />
<Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
</Target>
这应该如何看待.NET 4.5?
我已阅读here使用ILMerge和.NET 4.5存在一些问题。
答案 0 :(得分:12)
我找不到任何关于此的好文档,但正如Matt Wrocks blog post和another question about ILMerge所建议的那样,我首先尝试使用与.NET 4相同的参考组件路径。
在将我们的NuGet包重新定位到.NET 4.5之前,这似乎首先起作用。 (特别是Microsoft.AspNet.WebApi.Client,它添加了对新的.NET 4.5程序集System.Net.Http.WebRequest的引用,之前它包含在NuGet包中。)
更新参考程序集到.NET 4.5的路径后,它工作正常:
C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.5
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release' ">
<CreateItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)'=='.dll'">
<Output ItemName="AssembliesToMerge" TaskParameter="Include" />
</CreateItem>
<PropertyGroup>
<ReferenceAssemblies>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5</ReferenceAssemblies>
</PropertyGroup>
<Message Importance="high" Text="Executing ILMerge...with target platform from $(ReferenceAssemblies)" />
<Exec Command=""$(SolutionDir)LIB\ILMerge.exe" /out:@(MainAssembly) /internalize /targetplatform:v4,"$(ReferenceAssemblies)" "@(IntermediateAssembly)" @(AssembliesToMerge->'"%(FullPath)"', ' ')" />
<Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
</Target>
在大多数情况下,.NET 4程序集的路径也可以工作,但在.NET 4.5中引用新程序集时,需要更新路径。
请注意,在示例中,ILMerge.exe被下载到解决方案目录中名为LIB的文件夹中。