我试图使用c# 4.0编译我的excel插件,并在Visual Studio中构建我的项目时开始遇到这个问题。重要的是要告诉你,我以前从来没有遇到过这个问题。什么会导致这种情况发生?
当前回答
I recently hit this problem. In my case, I have NuGet packages on different assemblies. What I had was different versions of the same NuGet packages associated with my own assemblies. My solution was to use the NuGet package manager upon the Solution, as opposed to the individual projects. This enables a "consolidation" option, where you can upgrade your NuGet packages across as many projects as you want - so they all reference the same version of the assembly. When I did the consolidations, the build failure disappeared.
其他回答
I recently hit this problem. In my case, I have NuGet packages on different assemblies. What I had was different versions of the same NuGet packages associated with my own assemblies. My solution was to use the NuGet package manager upon the Solution, as opposed to the individual projects. This enables a "consolidation" option, where you can upgrade your NuGet packages across as many projects as you want - so they all reference the same version of the assembly. When I did the consolidations, the build failure disappeared.
这里有一个不同的方法来解决这个问题:
右键单击项目并选择“卸载项目”选项。您将注意到您的项目变得不可用。 右键单击不可用项目并选择“Edit”选项。 向下滚动到包含所有资源标记的“< ItemGroup >”标记。 现在转到已经显示在错误列表中的引用,您将注意到它使用了单个标记(即< reference Include="assemble_name_here, Version=0.0.0.0, Culture=neutral" / >)。 更改为如下所示:
.
<Reference Include="assemble_name_here, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" >
< Private > True < / Private >
< HintPath > path_here\assemble_name_here.dll < / HintPath >
< / Reference >
保存您的更改,再次右键单击不可用的项目,然后单击“重新加载项目”选项,然后构建。
尝试update-package -重装-ignoredependencies
我在从包中迁移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文件版本更新(或者你不会得到更新)时,这将不得不重复,但我希望它能很快得到修复…
如果你试了这个问题的所有其他答案,你会:
您的解决方案中有多个项目 有一个项目(项目a)引用另一个项目(项目B),后者的项目引用一个NuGet包。 在项目A中,您使用Intellisense/ReSharper引入项目B中引用的NuGet包的引用(当项目B中的方法返回由NuGet包提供的类型并且该方法在项目A中使用时,这可能会发生) 通过NuGet包管理器(或CLI)更新NuGet包。
...你可能在你的项目的引用中有不同版本的NuGet包DLL,因为Intellisense/ReSharper创建的引用将是一个“正常的”引用,而不是预期的NuGet引用,所以NuGet更新过程不会发现或更新它!
要解决这个问题,请删除项目A中的引用,然后使用NuGet安装它,并确保所有项目中的NuGet包都是相同的版本。(如回答中所述)
生活小贴士:
当ReSharper/Intellisense建议添加一个引用到你的项目时,这个问题就会出现。它可能比上面的例子复杂得多,多个交织的项目和依赖关系使其难以跟踪。如果ReSharper/Intellisense建议的引用实际上来自NuGet包,使用NuGet来安装它。
推荐文章
- 如何转换列表<字符串>列表<int>?
- c#对象列表,我如何得到一个属性的和
- 我如何使用IValidatableObject?
- 如何指定最小值,但没有使用范围数据注释属性的最大小数?
- c# vs Java Enum(适合c#新手)
- c#消毒文件名
- 在EF中更新父实体时如何添加/更新子实体
- ASP。NET身份的默认密码散列器-它是如何工作的,它是安全的?
- 如何写一个JSON文件在c# ?
- 静态隐式运算符
- 不区分大小写列表搜索
- 'throw'和'throw new Exception()'的区别
- 不能在lambda表达式中使用ref或out参数
- c# int到字节[]
- 将WPF组合框绑定到自定义列表