You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 10:15:14