Click Once 和 .NET Standard 兼容性问题
最近使用Click Once打包使用.NET Standard库的WPF应用时,出现一些无法加载库文件的异常,例如:
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/529
关于.NET Standard lib引用说明的文章:https://andrewlock.net/what-is-the-netstandard-library-metapackage/
微软给出了一个Workaround:
在***.csproj中添加如下代码,即可解决
<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>