Azure 管道错误:找不到类型或命名空间名称“Azure”(是否缺少 using 指令或程序集引用?

问题描述 投票:0回答:3

我在 azure devops 中有一个构建管道,但出现以下错误。

找不到类型或命名空间名称“Azure”(您是否缺少 using 指令还是程序集引用?

在我的 MSbuild 任务期间出现此错误,之前的 Nuget 恢复任务工作正常。

这是我的项目文件

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
  <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>{01511C7D-0BB5-4EF9-9B86-FE2B7B1E73DB}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>GraphSDK</RootNamespace>
    <AssemblyName>GraphSDK</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <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' ">
    <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.Drawing" />
    <Reference Include="System.IdentityModel" />
    <Reference Include="System.Numerics" />
    <Reference Include="System.Security" />
    <Reference Include="System.Windows.Forms" />
    <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="GraphClient.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Samples\Assignment.cs" />
    <Compile Include="Samples\Submission.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="app.config" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Identity">
      <Version>1.5.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Graph">
      <Version>4.7.0</Version>
    </PackageReference>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

这是我的MSbuild task,知道错误的原因是什么或者可能与我的项目相关吗?

顺便说一句,它在 VS2019 中本地构建得很好。

azure-devops azure-pipelines
3个回答
2
投票

我是怎么解决的?

您的项目采用 nuget 包的方式似乎有所不同。

我是从解决方案级别添加它们的。

  1. 右键单击解决方案。
  2. 管理解决方案的 Nuget 包...

有效的方法是删除 Nuget 包并从项目级别添加回来(我的解决方案中有 3 个项目)。

  1. 右键单击该项目。
  2. 管理 Nuget 包..
  3. 并安装回所有软件包(逐个项目)。

不知道为什么,但它有效!


1
投票

对我来说,HintPath 不正确 - 我有两个单独的 A.sln 和 B.sln 文件引用相同的 common.csproj 公共代码。

为了解决这个问题,我更新了 common.csproj 中的 HintPath,因为我正在为 A.sln 进行 Nuget 恢复,但 HintPath 指向 B.sln 的 \packages\ 文件夹。

这可能会产生与我删除包并将其重新添加到 A.sln 相同的效果(如上面的答案),因为它可能会更新 HintPath。

希望有帮助!


0
投票

在我的场景中,我正在处理两个项目,即 ProjectOne.slnProjectTwo.sln,它们共享 ProjectCommon.csproj
该问题是由于某些软件包的

<HintPath>
被引用为
..\packages\
。由于这是共享路径,所以我通过将其从
..\packages\
修改为
$(SolutionDir)\packages\
来解决该问题,成功解决了问题。

添加屏幕截图以供参考:

© www.soinside.com 2019 - 2024. All rights reserved.