我在我的 .csproj 文件中使用PackageReference并且我的构建在 Visual Studio (2017) 中工作。我正在使用 .net 4.5 构建我看过这个:
(使用 jenkins 构建时,MSBuild 没有为 nuget PackageReference 添加 /reference)
起初我在我们的构建服务器上遇到了问题,所以我在我的计算机上本地尝试了它。我先进行还原,然后再进行构建(或重建)。错误是:
(CoreCompile 目标)-> Properties\AssemblyInfo.cs(25,12):错误 CS0246:找不到类型或命名空间名称“log4net”(您是否缺少 using 指令或程序集引用?)
在我的项目中,我有
<ItemGroup>
<PackageReference Include="log4net">
<Version>2.0.12</Version>
</PackageReference>
提前致谢。
更新
我创建了一个简单的解决方案/项目,其中仅包含一个 Nuget 包。我还使用最新的框架创建了它,以防与问题有关。同样,它在 VS2017 中构建,但使用 MSBuild 失败,.csproj 文件是
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>
<ProjectGuid>{9A64612A-63A2-4CA5-8470-75DD978D7449}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>testNetwonNugetProject</RootNamespace>
<AssemblyName>testNetwonNugetProject</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
我验证了在恢复时文件被添加到项目 obj 文件夹以及 user/roaming/nuget 和 user/.nuget/packages。我收到与上述相同的错误消息。