Windows 存储应用程序 DLL 32 位和 64 位
Windows Store App DLL 32bit and 64bit
我编写了一个小型 Media Foundation Transform 并将 C++ DLL 添加到我的 C# Windows Store App 项目.
32 位版本的 DLL 运行 x86 配置工作正常但 x64 不工作(它抛出异常并显示以下消息:
"MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED : HRESULT - 0x800700C1")
如果我添加 64 位版本,它是相同的,只是 x64 可以工作而 x86 不能。
有什么方法可以设置它,以便它对 x86 配置使用 x86 版本的 DLL,对 x64 配置使用 x64 版本的 DLL?
我花了一些时间,但我想出了如何使用 NuGet 来完成它。
首先,我在我的电脑上添加了一个位置作为包源,如 here 所述。
在 VS2013 CE 中,您可以通过打开 NuGet 包管理器设置(工具 > NuGet 包管理器 > 包管理器设置)并在包源下添加计算机上的位置来执行此操作。
为了创建 NuGet,我合并了几个 HowTo,因为一个单独的方法不起作用。
主要的是 this.
我为我需要的平台构建了 dll 并创建了以下文件夹结构
因为 ProjectName.props 和 ProjectName.targets 位于 netcore451 文件夹中可能有点难看。
lib中的.dll、.pri和.winmd是x86版本。根据 HowTo,它是多余的,您可以忽略这些文件,但如果没有它们,VS 可能无法在设计模式下正常工作。
在包含 build 和 lib 的文件夹中我创建了一个文件 ProjectName.nuspec
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>ProjectName</id>
<version>1.0.0</version>
<authors>Stefan Fabian</authors>
<owners>Stefan Fabian</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Description</description>
<releaseNotes>First release.</releaseNotes>
<copyright>Copyright 2015</copyright>
<references>
<group targetFramework=".NETCore4.5.1">
<reference file="ProjectName.winmd" />
</group>
</references>
</metadata>
</package>
ProjectName.props
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
ProjectName.targets
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PlatformCheck" BeforeTargets="InjectReference"
Condition=" ( ('$(Platform)' != 'x86') AND ('$(Platform)' != 'AMD64') AND ('$(Platform)' != 'Win32') AND ('$(Platform)' != 'ARM') AND ('$(Platform)' != 'x64') )">
<Error Text="$(MSBuildThisFileName) does not work correctly on '$(Platform)'
platform. You need to specify platform (x86 / x64 or ARM)." />
</Target>
<Target Name="InjectReference" BeforeTargets="ResolveAssemblyReferences">
<ItemGroup Condition="'$(Platform)' == 'x86' or '$(Platform)' == 'Win32'">
<Reference Include="ProjectName">
<HintPath>$(MSBuildThisFileDirectory)x86\ProjectName.winmd</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'x64' or '$(Platform)' == 'AMD64'">
<Reference Include="ProjectName">
<HintPath>$(MSBuildThisFileDirectory)x64\ProjectName.winmd</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'ARM'">
<Reference Include="ProjectName">
<HintPath>$(MSBuildThisFileDirectory)ARM\ProjectName.winmd</HintPath>
</Reference>
</ItemGroup>
</Target>
</Project>
我不确定是否有必要检查 x86 和 Win32,但它对我有用。
免责声明
这是我第一次创建 NuGet 包,上面的代码可能很糟糕。
我编写了一个小型 Media Foundation Transform 并将 C++ DLL 添加到我的 C# Windows Store App 项目.
32 位版本的 DLL 运行 x86 配置工作正常但 x64 不工作(它抛出异常并显示以下消息:
"MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED : HRESULT - 0x800700C1")
如果我添加 64 位版本,它是相同的,只是 x64 可以工作而 x86 不能。
有什么方法可以设置它,以便它对 x86 配置使用 x86 版本的 DLL,对 x64 配置使用 x64 版本的 DLL?
我花了一些时间,但我想出了如何使用 NuGet 来完成它。 首先,我在我的电脑上添加了一个位置作为包源,如 here 所述。
在 VS2013 CE 中,您可以通过打开 NuGet 包管理器设置(工具 > NuGet 包管理器 > 包管理器设置)并在包源下添加计算机上的位置来执行此操作。
为了创建 NuGet,我合并了几个 HowTo,因为一个单独的方法不起作用。 主要的是 this.
我为我需要的平台构建了 dll 并创建了以下文件夹结构
因为 ProjectName.props 和 ProjectName.targets 位于 netcore451 文件夹中可能有点难看。 lib中的.dll、.pri和.winmd是x86版本。根据 HowTo,它是多余的,您可以忽略这些文件,但如果没有它们,VS 可能无法在设计模式下正常工作。
在包含 build 和 lib 的文件夹中我创建了一个文件 ProjectName.nuspec
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>ProjectName</id>
<version>1.0.0</version>
<authors>Stefan Fabian</authors>
<owners>Stefan Fabian</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Description</description>
<releaseNotes>First release.</releaseNotes>
<copyright>Copyright 2015</copyright>
<references>
<group targetFramework=".NETCore4.5.1">
<reference file="ProjectName.winmd" />
</group>
</references>
</metadata>
</package>
ProjectName.props
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
ProjectName.targets
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PlatformCheck" BeforeTargets="InjectReference"
Condition=" ( ('$(Platform)' != 'x86') AND ('$(Platform)' != 'AMD64') AND ('$(Platform)' != 'Win32') AND ('$(Platform)' != 'ARM') AND ('$(Platform)' != 'x64') )">
<Error Text="$(MSBuildThisFileName) does not work correctly on '$(Platform)'
platform. You need to specify platform (x86 / x64 or ARM)." />
</Target>
<Target Name="InjectReference" BeforeTargets="ResolveAssemblyReferences">
<ItemGroup Condition="'$(Platform)' == 'x86' or '$(Platform)' == 'Win32'">
<Reference Include="ProjectName">
<HintPath>$(MSBuildThisFileDirectory)x86\ProjectName.winmd</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'x64' or '$(Platform)' == 'AMD64'">
<Reference Include="ProjectName">
<HintPath>$(MSBuildThisFileDirectory)x64\ProjectName.winmd</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'ARM'">
<Reference Include="ProjectName">
<HintPath>$(MSBuildThisFileDirectory)ARM\ProjectName.winmd</HintPath>
</Reference>
</ItemGroup>
</Target>
</Project>
我不确定是否有必要检查 x86 和 Win32,但它对我有用。
免责声明
这是我第一次创建 NuGet 包,上面的代码可能很糟糕。