我正在尝试使用 Visual Studio 2019 和 Visual Studio 2017 打开一个解决方案。解决方案中的所有项目都在加载,除了一个。尝试加载已卸载的项目时,我在输出窗口中收到错误消息
<块引用>TakstMVC.csproj : error : 导入的项目 “....build\MSBuild.Community.Tasks.targets”未找到。确认 导入声明中的表达式 “TakstMVC\.....build\MSBuild.Community.Tasks.targets”是正确的, 并且该文件存在于磁盘上。 TakstMVC\FluentMigrator.targets
当我尝试使用 VS 2017 打开时,我看到了一份迁移报告,上面写着
<块引用>TakstMVC.csproj:该项目类型所基于的应用程序 没有找到。请尝试此链接以获取更多信息: http://go.microsoft.com/fwlink/?LinkID=299083&projecttype=E3E379DF-F4C6-4180-9B81-6769533ABE47
项目部分.csproj如下:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A4354F5C-ECF5-4621-AA9E-B91FE543F096}</ProjectGuid>
<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TakstMVC</RootNamespace>
<AssemblyName>TakstMVC</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>true</UseIISExpress>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>4.0</OldToolsVersion>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<MvcProjectUpgradeChecked>true</MvcProjectUpgradeChecked>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
我的电脑上安装了以下软件
我尝试安装 dotnetfx35.exe,但它在执行时甚至没有运行(甚至没有消息或错误)。
窗口功能如下:
如何识别项目的目标框架并成功加载到visual studio?感谢您在这方面的一些建议。
答案 0 :(得分:0)
错误很明显,您没有在本地正确导入 MSBuild.Community.Tasks.targets
。原因是您没有在 PC 上安装 MSBuild.Community.Tasks.targets
或 csproj
文件的导入路径不正确。
您应该check this document安装正确的目标。
首先,删除 csproj
文件下的 xml 节点,如下所示:
<Import Project="..\build\MSBuild.Community.Tasks.targets" Condition="Exists('..\build\MSBuild.Community.Tasks.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\build\MSBuild.Community.Tasks.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\build\MSBuild.Community.Tasks.targets'))" />
</Target>
然后,在 csproj 文件下添加这些:
<Import Project="C:\Program Files (x86)\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
除此之外,您还可以使用 nuget 函数。首先,如果项目上有旧版本,请卸载 nuget 包。然后,使用第一个建议删除任何以前的 import projects="xxx\MSBuildTasks.targets"
。之后,安装 MSBuildTasks nuget package。那是一样的。
更新
尝试您应该将 ..\..\
更改为 ..\
。使用正确的路径。
或在工具-->Nuget Package Manager-->Package Manager Console下使用此命令/p>
update-package -reinstall
令人尴尬的是,整个问题都出在我的解决方案位于本地计算机中的解决方案路径上。我有一个很长的路径,包括一个也有两个词的文件夹。在尝试了所有其他方法后,我将解决方案文件夹移动到 C:\temp 文件夹,问题不再存在。 VS 中显示的错误非常具有误导性。多么宝贵的时间啊。感谢您的努力!