使用jenkins构建时,MSBuild不为nuget PackageReference添加/ reference

时间:2019-02-11 17:40:19

标签: jenkins nuget msbuild-15

我有一个jenkins构建,可以清理,还原然后构建一个单元测试项目。该项目以及我的其他项目最近已迁移为使用PackageReference。清理工作和还原工作。我验证了%userprofile%/.nuget/packages/中是否存在NUnit。这是我的构建脚本中的命令:

msbuild /p:Configuration="Debug" /t:clean OtherProjectName.Test.csproj
msbuild /p:Configuration="Debug" /t:restore OtherProjectName.Test.csproj
msbuild /p:Configuration="Debug" OtherProjectName.Test.csproj

稍后会导致输出看起来像这样:

csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+
     /reference:<one of my references> /reference:<another one> /reference:<and so on>
     /out:obj\Debug\OtherProjectName.Test.dll /subsystemversion:6.00 /target:library /utf8output <a list of source files>

我的项目的构建失败,因为找不到NUnit(请参见下文)。我相信它找不到NUnit,因为编译命令不包含对NUnit nuget包的“ /引用”。

error CS0246: The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?

我的其他项目的NuGet软件包确实具有“ /引用”。因此,我比较了它们,看是否有明显不同的地方。我确实注意到我的大多数项目一开始都包含以下内容:

<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

基于我对该行的简要了解,我认为这可能是罪魁祸首,但是当我在本地计算机上尝试相同的步骤(它具有VS2017和MSbuild 15,就像jenkins服务器一样)时,我无法复制问题。

我的.csproj文件具有以下内容:

    <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{a guid}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>OtherProjectName.Test</RootNamespace>
    <AssemblyName>OtherProjectName.Test</AssemblyName>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
    <IsCodedUITest>False</IsCodedUITest>
    <TestProjectType>UnitTest</TestProjectType>
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <!-- a couple entries like this -->
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="log4net">
      <HintPath>Z:\path\to\log4net.dll</HintPath>
    </Reference>
    <!-- a couple references like this -->
    <Reference Include="System" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Web.Extensions" />
    <Reference Include="System.Xml" />
    <Reference Include="WindowsBase" />
  </ItemGroup>
  <Choose>
    <When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
      <ItemGroup>
        <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
      </ItemGroup>
    </When>
    <Otherwise />
  </Choose>
  <ItemGroup>
    <!-- all my C# source files -->
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\OtherProjectName\OtherProjectName.csproj">
      <Project>{a guid}</Project>
      <Name>OtherProjectName</Name>
    </ProjectReference>
    <ProjectReference Include="..\OtherProjectName2\OtherProjectName2.csproj">
      <Project>{another guid}</Project>
      <Name>OtherProjectName2</Name>
    </ProjectReference>
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config">
      <SubType>Designer</SubType>
    </None>
    <None Include="App.config.1" />
    <None Include="Unit Test Playlists\Fast.playlist" />
    <!-- all my unit test playlists -->
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="NUnit">
      <Version>3.11.0</Version>
    </PackageReference>
    <PackageReference Include="NUnit.ConsoleRunner">
      <Version>3.9.0</Version>
    </PackageReference>
    <PackageReference Include="NUnit3TestAdapter">
      <Version>3.11.0</Version>
    </PackageReference>
    <!-- other nuget packages -->
  </ItemGroup>
  <Choose>
    <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
      <ItemGroup>
        <Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
          <Private>False</Private>
        </Reference>
        <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
          <Private>False</Private>
        </Reference>
        <Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
          <Private>False</Private>
        </Reference>
        <Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
          <Private>False</Private>
        </Reference>
      </ItemGroup>
    </When>
  </Choose>
  <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- 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>

1 个答案:

答案 0 :(得分:1)

请比较本地服务器和构建服务器上的MSBUILD版本。看起来您可能在不支持程序包引用的生成服务器上运行了较低版本的MSBUILD。