首页 文章

如何在面向net462框架的.Net Core项目中使用ConfigurationPropertyAttribute?

提问于
浏览
1

我正在尝试使用Visual Studio Code编译一个小项目,该项目是使用Visual Studio 2017创建的普通.Net项目 . 无法找到其中一个类ConfigurationPropertyAttribute,我想知道应该添加哪个引用以使其编译 .

我尝试在NuGet中使用反向搜索来搜索此类,但它似乎不存在 .

这是我的.Net核心项目:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net462</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="microsoft.extensions.configuration" Version="1.1.2" />
  </ItemGroup>
</Project>

我的最终目标是简单地使用Visual Studio Code而不是Visual Studio 2017来编译和调试旧项目,而不必使用.Net Core,因为它仍然缺少许多功能 . 我认为通过定位net462,我可以访问.Net 4.6.2中的所有内容,但似乎并非如此 . 我错过了什么或者有什么我不理解的东西吗?

1 回答

  • 2

    你的.csproj文件需要添加一个引用 System.Configuration 而不是一个PackageRefrence Microsoft.Extensions.Configuration

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net462</TargetFramework>
      </PropertyGroup>
    
      <ItemGroup>
        <Reference Include="System.Configuration" />
      </ItemGroup>
    
    </Project>
    

相关问题