在我将 NuGet.Core 包作为 PackageReference 添加到我的 csproj 后,我没有任何效果
After I add NuGet.Core package to my csproj as PackageReference, I have no any effect
在我将 NuGet.Core
包作为 PackageReference 添加到我的 csproj 后,我没有任何效果。接下来我描述复制步骤和我的项目文件夹内容。我的问题:我是在做错事还是 dotnet cli 错误?我注册了一个 issue 并将跟踪这两个问题 - 这个问题和问题。
重现步骤:
dotnet new console
- 将
csproj
文件中的 TargetFramework
更改为 net461
dotnet add package NuGet.Core
- 将
using NuGet
添加到Program.cs
(这个命名空间存在于NuGet.Core程序集中,我检查过)
dotnet restore
dotnet build
结果:一个错误"The type or namespace name 'NuGet' could not be found"。
我的项目目录的全部内容:
nuget-tree.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGet.Core" Version="2.14.0" />
</ItemGroup>
</Project>
Program.cs:
using System;
using NuGet;
namespace nuget_tree
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
.NET CLI 工具版本: 我都试过了:1.0.4
和 2.0.0-preview2-25407-01
我发现问题不在 dotnet CLI 中,而是在 nuget 中。我执行以下操作:
- 2015 年 Visual Studio 创建了一个控制台应用程序
- 在程序包管理器控制台中:
PM> Install-Package Microsoft.Web.Xdt -Version 2.1.0
PM> Install-Package NuGet.Core -Version 2.13.1
效果很好。但是,如果我安装了最新版本的 NuGet.Core
,那么在 NuGet.Core 子文件夹的 packages 目录中,没有包含程序集的 lib
文件夹。所以我不能在项目中引用它。这一切看起来很奇怪。然后 我决定清除 nuget 缓存。这解决了我的问题。 清除缓存后,我可以创建一个新项目并成功使用最新的 NuGet.Core。
清除缓存我使用了:
nuget locals all -list
- 列出本地缓存
nuget locals all -clear
- 清除所有缓存
在我将 NuGet.Core
包作为 PackageReference 添加到我的 csproj 后,我没有任何效果。接下来我描述复制步骤和我的项目文件夹内容。我的问题:我是在做错事还是 dotnet cli 错误?我注册了一个 issue 并将跟踪这两个问题 - 这个问题和问题。
重现步骤:
dotnet new console
- 将
csproj
文件中的TargetFramework
更改为net461
dotnet add package NuGet.Core
- 将
using NuGet
添加到Program.cs
(这个命名空间存在于NuGet.Core程序集中,我检查过) dotnet restore
dotnet build
结果:一个错误"The type or namespace name 'NuGet' could not be found"。
我的项目目录的全部内容:
nuget-tree.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGet.Core" Version="2.14.0" />
</ItemGroup>
</Project>
Program.cs:
using System;
using NuGet;
namespace nuget_tree
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
.NET CLI 工具版本: 我都试过了:1.0.4
和 2.0.0-preview2-25407-01
我发现问题不在 dotnet CLI 中,而是在 nuget 中。我执行以下操作:
- 2015 年 Visual Studio 创建了一个控制台应用程序
- 在程序包管理器控制台中:
PM> Install-Package Microsoft.Web.Xdt -Version 2.1.0
PM> Install-Package NuGet.Core -Version 2.13.1
效果很好。但是,如果我安装了最新版本的 NuGet.Core
,那么在 NuGet.Core 子文件夹的 packages 目录中,没有包含程序集的 lib
文件夹。所以我不能在项目中引用它。这一切看起来很奇怪。然后 我决定清除 nuget 缓存。这解决了我的问题。 清除缓存后,我可以创建一个新项目并成功使用最新的 NuGet.Core。
清除缓存我使用了:
nuget locals all -list
- 列出本地缓存nuget locals all -clear
- 清除所有缓存