Release模式构建时无法加载Windows.winmd引用的问题
Release模式加载Windows.winmd失败问题排查
我在项目中引入了一个依赖Windows.winmd的NuGet包,Debug模式下构建运行完全正常,但切换到Release模式构建时直接失败,报错信息如下:
Error Could not load file or assembly 'file:///C:\Users\myrepo\packages\thepackage\lib\net47\Windows.winmd' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
经排查问题确实由.winmd文件引发,我试过多种常见解决方案,但都没有效果:
- 检查GenerateManifests相关设置:生成选项和发布页面里找不到安全选项卡,确认未启用该功能,无效。
- 验证Windows.winmd文件状态:文件未被Windows阻止,也不存在缺失情况,无效。
- 启用loadFromRemoteSources配置:文件存放在本地的packages目录下,并非网络来源文件,该设置起不到作用。
- 临时改用Debug配置构建:虽然能正常运行,但违背了Release构建的初衷,不是可行解决方案。
- 调整引用属性与路径:将该引用的Copy Local设为false,尝试把Windows.winmd添加到Framework SDK文件列表中,也更换过不同的引用路径,错误依然存在。
- 对比Debug和Release配置:逐一检查构建设置页面的差异,直接对比.csproj文件内容,未找到能解决问题的配置差异。
项目的.csproj中相关配置如下:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <CodeAnalysisRuleSet>SecurityRules.ruleset</CodeAnalysisRuleSet> <PublishDatabaseSettings> </PublishDatabaseSettings> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <ExcludeGeneratedDebugSymbol>false</ExcludeGeneratedDebugSymbol> <LegacyPublishPropertiesPageEnabled>true</LegacyPublishPropertiesPageEnabled> <RegisterForComInterop>false</RegisterForComInterop> <PublishDatabases>true</PublishDatabases> </PropertyGroup>
项目使用的.NET版本:.NET Framework 4.7.2
内容的提问来源于stack exchange,提问作者SyndRain
相关产品推荐
相关产品推荐

