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

时间:2017-06-13 23:50:41

标签: c# .net visual-studio-code .net-core

我正在尝试使用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 个答案:

答案 0 :(得分: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>