Click Once 和 .NET Standard 兼容性問題

Click Once 和 .NET Standard 兼容性問題

最近使用Click Once打包使用.NET Standard庫的WPF應用時,出現一些沒法加載庫文件的異常,例如:git

Unable to initialize the application (Could not load file or assembly 'System.Runtime, Version=4.1.1.0, Culture=neutral, 
PublicKeyToken=b03f5f7f11d50a3a
' or one of its dependencies. The System cannot find the file specified.

這是一個Bug,https://github.com/dotnet/standard/issues/529github

關於.NET Standard lib引用說明的文章:https://andrewlock.net/what-is-the-netstandard-library-metapackage/app

 

微軟給出了一個Workaround:spa

 

在***.csproj中添加以下代碼,便可解決.net

<ItemGroup>
    <PublishFile Include="netfx.force.conflicts">
      <Visible>False</Visible>
      <PublishState>Exclude</PublishState>
      <IncludeHash>True</IncludeHash>
      <FileType>Assembly</FileType>
    </PublishFile>
  </ItemGroup>
  <Target Name="FixClickOnceDependencies" BeforeTargets="_DeploymentComputeClickOnceManifestInfo">
    <ItemGroup>
      <_noCopyRefs Include="@(ReferencePath)" Condition="'%(ReferencePath.Private)' == 'false'" />
      <_noCopyRefsByFileName Include="@(_noCopyRefs->'%(FileName)')">
        <OriginalItem>%(Identity)</OriginalItem>
      </_noCopyRefsByFileName>
      <_libByFileName Include="@(ReferenceCopyLocalPaths->'%(FileName)')">
        <OriginalItem>%(Identity)</OriginalItem>
      </_libByFileName>
      <_overlappingRefByFileName Include="@(_noCopyRefsByFileName)" Condition="'@(_noCopyRefsByFileName)' == '@(_libByFileName)' AND '%(Identity)' != ''" />
      <_overlappingLibByFileName Include="@(_libByFileName)" Condition="'@(_noCopyRefsByFileName)' == '@(_libByFileName)' AND '%(Identity)' != ''" />
      <_overlappingRef Include="@(_overlappingRefByFileName->'%(OriginalItem)')" />
      <_overlappingLib Include="@(_overlappingLibByFileName->'%(OriginalItem)')" />
    </ItemGroup>
    <ItemGroup Condition="'@(_overlappingRef)' != ''">
      <ReferencePath Remove="@(_overlappingRef)" />
      <ReferencePath Include="@(_overlappingLib)">
        <Private>True</Private>
      </ReferencePath>
    </ItemGroup>
  </Target>
相關文章
相關標籤/搜索