基于平台类型构建项目
Building projects based on platform type
我的项目可以为 x64、x86 和 ARM (WinRT) 构建,引用特定于平台的库(也基于 x64、x86 和 ARM)。
为了有条件地构建特定于平台的 DLL,我手动编辑了 .csproj 文件以包含这些特定于平台的 DLL 的元素,如下所示:
<ItemGroup Condition="'$(Platform)' == 'x86'">
<Reference Include="PortablePlatform">
<HintPath>..\..\packages\LibraryName\x86\PortablePlatform.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'x64'">
<Reference Include="PortablePlatform">
<HintPath>..\..\packages\LibraryName\x64\PortablePlatform.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'ARM'">
<Reference Include="PortablePlatform">
<HintPath>..\..\packages\LibraryName\ARM\PortablePlatform.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
现在,我可以编译我的解决方案了。但是,在运行时它在加载特定于平台的 DLL (PortablePlatform.dll) 时出错,并且在 xamlTypeInfo.g.cs:
中的 GetXamlType 的 return 语句中抛出错误
public global::Windows.UI.Xaml.Markup.IXamlType GetXamlType(global::System.Type type)
{
if(_provider == null)
{
_provider = new global::<ABC>_App_XamlTypeInfo.XamlTypeInfoProvider();
}
return _provider.GetXamlTypeByType(type);
}
错误堆栈如下:
.WinRT.App.exe 中发生类型 'System.IO.FileNotFoundException' 的异常,但未在用户代码中处理
附加信息:无法加载文件或程序集 'PortablePlatform, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null' 或其依赖项之一。系统找不到指定的文件。
我能够弄清楚这个问题。我必须从 csproj 文件的 <Reference>
元素中删除 <Private>True/False</Private>
。不太确定,但我认为这是导致在运行时加载之前构建的 dll。
我的项目可以为 x64、x86 和 ARM (WinRT) 构建,引用特定于平台的库(也基于 x64、x86 和 ARM)。 为了有条件地构建特定于平台的 DLL,我手动编辑了 .csproj 文件以包含这些特定于平台的 DLL 的元素,如下所示:
<ItemGroup Condition="'$(Platform)' == 'x86'">
<Reference Include="PortablePlatform">
<HintPath>..\..\packages\LibraryName\x86\PortablePlatform.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'x64'">
<Reference Include="PortablePlatform">
<HintPath>..\..\packages\LibraryName\x64\PortablePlatform.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'ARM'">
<Reference Include="PortablePlatform">
<HintPath>..\..\packages\LibraryName\ARM\PortablePlatform.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
现在,我可以编译我的解决方案了。但是,在运行时它在加载特定于平台的 DLL (PortablePlatform.dll) 时出错,并且在 xamlTypeInfo.g.cs:
中的 GetXamlType 的 return 语句中抛出错误public global::Windows.UI.Xaml.Markup.IXamlType GetXamlType(global::System.Type type)
{
if(_provider == null)
{
_provider = new global::<ABC>_App_XamlTypeInfo.XamlTypeInfoProvider();
}
return _provider.GetXamlTypeByType(type);
}
错误堆栈如下: .WinRT.App.exe 中发生类型 'System.IO.FileNotFoundException' 的异常,但未在用户代码中处理 附加信息:无法加载文件或程序集 'PortablePlatform, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null' 或其依赖项之一。系统找不到指定的文件。
我能够弄清楚这个问题。我必须从 csproj 文件的 <Reference>
元素中删除 <Private>True/False</Private>
。不太确定,但我认为这是导致在运行时加载之前构建的 dll。