我在 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>
顺便说一句,它在 VS2019 中本地构建得很好。
我是怎么解决的?
您的项目采用 nuget 包的方式似乎有所不同。
我是从解决方案级别添加它们的。
有效的方法是删除 Nuget 包并从项目级别添加回来(我的解决方案中有 3 个项目)。
不知道为什么,但它有效!
对我来说,HintPath 不正确 - 我有两个单独的 A.sln 和 B.sln 文件引用相同的 common.csproj 公共代码。
为了解决这个问题,我更新了 common.csproj 中的 HintPath,因为我正在为 A.sln 进行 Nuget 恢复,但 HintPath 指向 B.sln 的 \packages\ 文件夹。
这可能会产生与我删除包并将其重新添加到 A.sln 相同的效果(如上面的答案),因为它可能会更新 HintPath。
希望有帮助!