我在 .csproj 中的引用(路径)有问题吗

Is there a problem with my references(paths) in .csproj

因为我没有编程技能,开发人员用VS2010为我开发了一个网站。为了变得独立,我最近切换到了最新的 (16.8.4) VS2019 社区。 现在我想删除VS2010版本,但是当我这样做时,VS2019版本报告构建错误问题。 一位荷兰论坛发帖人帮助我将 .sln 和 .csproj 文件修改为 运行 with VS2019 without VS2010。 不幸的是,我们似乎都错过了使用 VS2019 构建项目的一些东西。

这是我现在的情况:

  1. 包含所有文件的项目文件夹运行与 VS2010 完美结合 所以,项目本身是可以的。
  2. 第二个项目文件夹,其中包含已修改的 .sln 和 .csproj 文件,但在 VS2019 中存在构建错误。
  3. 我可以 运行 VS2010 .csproj 与 VS2019,但前提是 VS2010 没有卸载。所以VS2019好像也可以。

我注意到 .csproj VS2019 中缺少与 VS2010 版本相关的引用。 仅将 .csproj 版本 VS2010 的所有引用粘贴(正如预期的那样)到 VS2019 并不能解决问题。 这可能是由错误的访问路径引起的还是有其他原因? (也许还有其他链接,但我不需要所有的东西,比如Github,目前在VS2010中实现的TourtoiseSVN和VisualSVN)

我尝试构建一个新的 .csproj 文件,但这对我来说太难了,所以我现在 运行 别无选择。 我遵循了这些建议: How can I recover a corrupt .csproj file in Visual Studio 2010?How to generate .csproj file in visual studio 2019? 并做了很多谷歌搜索并浏览了有关相关 .csproj 问题的帖子。 实际上我花了几天时间寻找解决方案。 我还在 Udemy.com(Basic C#)

开始了在线培训课程

如果有人愿意通过我的 .csproj 文件找出问题的原因,我将不胜感激。

References of original working project in VS2010 Ultimate:  
0]  !
1]  System  
2]  System.Configuration    
3]  System.Data
4]  System.Data.DataSetExtensions   
5]  System.Drawing  
6]  System.EnterpriseServices   .
7]  System.Web
8]  System.Web.DynamicData  
9]  System.Web.Entity   
10] System.Web.Extensions   
11] System.Web.Services 
12] System.Xml
13] System.Xml.Linq

References of not working project in VS2019 Community:
0]  Zr= Analyzers
1]  System
2]  System.Configuration
3]  System.Data
4]  missing
5]  System.Drawing 
6]  System.EnterpriseServices
7]  System.Web
8]  System.Web.DynamicData
9]  System.Web.Entity
10] missing
11] System.Web.Services
12] System.Xml
13] missing

这是我剥离的 .csproj 文件(出于缩短的原因,我删除了大部分网页条目)

'''

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{736AF0B8-36E1-4F7B-B2EB-DA11038B90FE}</ProjectGuid>
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Website</RootNamespace>
    <AssemblyName>Website</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <TargetFrameworkProfile />
    <UseIISExpress>false</UseIISExpress>
    <SccProjectName> </SccProjectName>
    <SccLocalPath> </SccLocalPath>
    <SccAuxPath> </SccAuxPath>
    <SccProvider> </SccProvider>
    <Use64BitIISExpress />
    <IISExpressSSLPort />
    <IISExpressAnonymousAuthentication />
    <IISExpressWindowsAuthentication />
    <IISExpressUseClassicPipelineMode />
    <UseGlobalApplicationHostFile />
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">16.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
  <ItemGroup>
    <Reference Include="System.Web.DynamicData" />
    <Reference Include="System.Web.Entity" />
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Web" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Web.Services" />
    <Reference Include="System.EnterpriseServices" />
  </ItemGroup>
   <ItemGroup>
    <Content Include="Master.Master" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="App_Code\" />
  </ItemGroup>
  <ItemGroup>
    <WCFMetadata Include="Connected Services\" />
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" />
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
        <WebProjectProperties>
          <UseIIS>False</UseIIS>
          <AutoAssignPort>False</AutoAssignPort>
          <DevelopmentServerPort>6919</DevelopmentServerPort>
          <DevelopmentServerVPath>/</DevelopmentServerVPath>
          <IISUrl>
          </IISUrl>
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>False</UseCustomServer>
          <CustomServerUrl>
          </CustomServerUrl>
         <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
        </WebProjectProperties>
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
  <!-- To  modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>  -->
</Project>

''' Msbuild 输出:

'''

Rebuild started...
1>------ Rebuild All started: Project: Website, Configuration: Release Any CPU ------
1>The "Configuration" property is a global property, and cannot be modified.
1>The "Platform" property is a global property, and cannot be modified.
1>Search paths being used for $(VSToolsPath) are C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0;$(MSBuildProgramFiles32)\MSBuild\Microsoft\VisualStudio\v$(VisualStudioVersion)
1>Trying to import C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets using extensions path C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0
1>Property reassignment: $(WebProjectOutputDirInsideProjectDefault)="False" (previous value: "True") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets (21,5)
1>Property reassignment: $(WebProjectOutputDir)="_PublishedWebsites\Website" (previous value: "E:\JohnDoe\Homepage JohnDoe\Development\JohnDoe\Relatie Voeding & Gedrag\Trunk vs2019 Testversie") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets (33,5)
1>Property reassignment: $(PrepareForRunDependsOn)="
1>      
1>      ;
1>      CopySilverlightApplications;
1>      _CopyBinDeployableAssemblies;
1>    ;
1>      _CopyWebApplication;
1>      _BuiltWebOutputGroupOutput
1>    " (previous value: "
1>      ;
1>      CopySilverlightApplications;
1>      _CopyBinDeployableAssemblies;
1>    ") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets (42,5)
1>Property reassignment: $(CleanDependsOn)="
1>      
1>      ;
1>      CleanWebProjectOutputDir;
1>    ;
1>      
1>      ;
1>      CleanWebsitesPackage;
1>      CleanWebsitesWPPAllFilesInSingleFolder;
1>      CleanWebPublishPipelineIntermediateOutput;
1>    ;
1>    " (previous value: "
1>      ;
1>      CleanWebProjectOutputDir;
1>    ") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets (212,5)
1>Property reassignment: $(PipelineDependsOn)="
1>      
1>      ;
1>      BeforeBuild;
1>      BuildOnlySettings;
1>      ResolveReferences;
1>      PrepareResourceNames;
1>      ComputeIntermediateSatelliteAssemblies;
1>      GetCopyToOutputDirectoryItems;
1>      _SGenCheckForOutputs;
1>    ;
1>      AfterBuild;
1>    " (previous value: "
1>      ;
1>      BeforeBuild;
1>      BuildOnlySettings;
1>      ResolveReferences;
1>      PrepareResourceNames;
1>      ComputeIntermediateSatelliteAssemblies;
1>      GetCopyToOutputDirectoryItems;
1>      _SGenCheckForOutputs;
1>    ") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets (355,5)
1>Property reassignment: $(WebProjectOutputDirInsideProjectDefault)="True" (previous value: "False") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets (398,5)
1>Property reassignment: $(WebProjectOutputDirInsideProjectDefault)="False" (previous value: "True") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets (399,5)
1>Property reassignment: $(_UseDefaultLinkExtensionValue)="True" (previous value: "False") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets (450,5)
1>Property reassignment: $(_DestinationIisAppPhysicalPath)="E:\JohnDoe\Homepage JohnDoe\Development\JohnDoe\Relatie Voeding & Gedrag\Trunk vs2019 Testversie_deploy" (previous value: "") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets (511,5)
1>Property reassignment: $(WriteItemsToSourceManifestDependsOn)="
1>      ;
1>      
1>      ;
1>      AddDatabasesToSourceManifest;
1>    ;
1>      AddIisSettingAndFileContentsToSourceManifest;
1>    " (previous value: "
1>      ;
1>      AddDatabasesToSourceManifest;
1>    ") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets (3492,5)
1>Property reassignment: $(DbDacFxPreviewDependsOn)="
1>      
1>      ;
1>      GetMSDeployInstalledVersionPath;
1>    ;
1>      RemoteDbDacFxPreview;
1>    " (previous value: "
1>      ;
1>      GetMSDeployInstalledVersionPath;
1>    ") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets (4462,5)
1>Property reassignment: $(PipelineTransformPhaseDependsOn)="
1>      ;
1>      ;
1>      PipeLineCollectFilesPhase;
1>      TransformWebConfig;
1>      ProfileTransformWebConfig;
1>      InsertAdditionalWebCofigConnectionStrings;
1>      MarkWebConfigAssistFilesAsExclude;
1>    ;_TransformWebConfigForAzureAuthentication" (previous value: "
1>      ;
1>      ;
1>      PipeLineCollectFilesPhase;
1>      TransformWebConfig;
1>      ProfileTransformWebConfig;
1>      InsertAdditionalWebCofigConnectionStrings;
1>      MarkWebConfigAssistFilesAsExclude;
1>    ") at C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing\ImportAfter\Microsoft.Web.AzureAD.Publishing.targets (17,5)
1>Property reassignment: $(OnBeforePipelineCollectFilesPhase)="
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

'''

旧的网络项目依赖于 2010 年网络平台安装程序安装的某些东西。它们已被提供相同或相似功能的 nuget 包所取代。

您有几个选择:

  • 卸载 vs2010 后,您可以重新安装网络平台安装程序包以确保您的系统上有正确的程序集
  • 卸载 vs2010 后,使用 'manage nuget references' 将缺少的引用作为 nuget 包安装到您的项目中。
  • 在您的系统上保留 vs2010... 如果需要,请使用 visual studio 2010 express for web。

为了提供更有针对性的帮助,请在尝试构建您的解决方案时共享 Msbuild 输出and/or您的解决方案的副本,可选择删除所有非必要文件以重现问题。

你的csproj文件在我这边,你丢失了系统默认的目标文件。

你应该使用这个:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>
    </ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{E29977D2-D61E-4223-BE04-D56AD8F15C88}</ProjectGuid>
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Website</RootNamespace>
    <AssemblyName>Website</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <TargetFrameworkProfile />
    <UseIISExpress>false</UseIISExpress>
    <SccProjectName>
    </SccProjectName>
    <SccLocalPath>
    </SccLocalPath>
    <SccAuxPath>
    </SccAuxPath>
    <SccProvider>
    </SccProvider>
    <Use64BitIISExpress />
    <IISExpressSSLPort />
    <IISExpressAnonymousAuthentication />
    <IISExpressWindowsAuthentication />
    <IISExpressUseClassicPipelineMode />
    <UseGlobalApplicationHostFile />
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">16.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>

    
    <!--add this targets file to make msbuild find the Build,Rebild,Clean target-->
    <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
    
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
  <ItemGroup>
    <Reference Include="System.Web.DynamicData" />
    <Reference Include="System.Web.Entity" />
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Web" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Web.Services" />
    <Reference Include="System.EnterpriseServices" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="Master.Master" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="App_Code\" />
  </ItemGroup>
  <ItemGroup>
    <WCFMetadata Include="Connected Services\" />
  </ItemGroup>
  <!--<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" />-->
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
        <WebProjectProperties>
          <UseIIS>False</UseIIS>
          <AutoAssignPort>False</AutoAssignPort>
          <DevelopmentServerPort>6919</DevelopmentServerPort>
          <DevelopmentServerVPath>/</DevelopmentServerVPath>
          <IISUrl>
          </IISUrl>
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>False</UseCustomServer>
          <CustomServerUrl>
          </CustomServerUrl>
          <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
        </WebProjectProperties>
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
  <!-- To  modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>  -->
</Project>

这是我在我的VS2019中测试过的项目,没有任何错误。如果它不起作用,您应该通过共享的 onedrive 或 public github 存储库与我们共享您的项目示例。大多数情况下,问题可能与您的项目文件和 proj 文件之间存在冲突。

@Perry Qian:太好了。那一行就成功了。该项目在 VS2019 中运行。因为我用 MicrosoftPlatformInstaller 安装了一些东西,所以我不得不进行一些删除并再次测试,然后我用 VS2010 重新安装了一个图像。使用卸载实用程序删除 VS2010 并再次测试。一切都好。 搜索正确答案 4 天后只有一行。 非常感谢。 (如果我以错误的方式回答,请道歉)