我试图使用c# 4.0编译我的excel插件,并在Visual Studio中构建我的项目时开始遇到这个问题。重要的是要告诉你,我以前从来没有遇到过这个问题。什么会导致这种情况发生?


当前回答

我就有这个问题。这是因为我有许多项目指向相同的组装,但从不同的版本。我解决它选择相同版本的所有项目在我的解决方案。

其他回答

您的程序集是否正确签名?

要检查这一点,在项目上按Alt+Enter(或右键单击,然后Properties)。点击“签名”。验证复选框“签名程序集”已选中,强名称密钥文件已选中,且“仅延迟签名”未选中。

您需要使用密钥对程序集进行签名。进入选项卡签名下的项目属性:

我去发布应用程序文件,发现dll抛出错误,将其从“包括(自动)”更改为“包括”。我现在可以发表了。

当我遇到这个问题时,我通过关闭“启用ClickOnce安全设置”来解决它。

菜单:项目|“项目名称”属性…|安全选项卡|“启用ClickOnce安全设置”复选框。

我在从包中迁移Excel插件后遇到了这个问题。配置到PackageReference。似乎和这个问题有关。

如果你不使用ClickOnce,下面的工作作为一个粗略的解决方案(它将从.manifest文件中省略所有依赖信息):

Unload project, edit .csproj Find the section looking like this: <!-- Include additional build rules for an Office application add-in. --> <Import Project="$(VSToolsPath)\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" Condition="'$(VSToolsPath)' != ''" /> Edit a renamed copy of the referenced .targets file (in my case, the file resolved to C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets and I made a copy Microsoft.VisualStudio.Tools.Office_FIX.targets in the same folder - didn't check if it works from a different folder). Find the GenerateApplicationManifest element and change its attribute Dependencies="@(DependenciesForGam)" to Dependencies="". Change the section found in 2. to reference your edited .targets file instead.

每当VS附带的.targets文件版本更新(或者你不会得到更新)时,这将不得不重复,但我希望它能很快得到修复…