我已经在我的latest project中添加了一个Xunit测试项目,该项目配置了Azure管道。我所有的测试都通过了,但是自从我添加了XUnit之后,VSBuild触发器就可以了:
错误:NETSDK1061:使用Microsoft.NETCore.App版本1.0.0还原了该项目,但在当前设置下,将改用版本2.0.9。要解决此问题,请确保将相同的设置用于还原以及后续操作(例如构建或发布)。通常,如果在生成或发布过程中设置了RuntimeIdentifier属性,但在还原过程中没有设置RuntimeIdentifier属性,则可能会发生此问题。有关更多信息,请参见https://aka.ms/dotnet-runtime-patch-selection。
我曾尝试对.csproj文件进行手动更改,然后还原,清理解决方案,但似乎无法找出导致断开连接的原因。
我的解决方案中有三个.csproj文件。我不确定如何解决他们的分歧。任何帮助将不胜感激,因为这是我下一个或两个月的个人项目,我希望尽早处理CI。
项目1-类库:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<OutputType>Library</OutputType>
</PropertyGroup>
</Project>
项目2-XUnit:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PlisskenLibrary\PlisskenLibrary.csproj" />
</ItemGroup>
</Project>
启动项目-控制台项目:
<?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>{D75CE556-EDB3-40ED-B836-168DAA5F12A7}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Plissken</RootNamespace>
<AssemblyName>Plissken</AssemblyName>
<TargetFrameworkVersion>v4.6.1</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="Properties\AssemblyInfo.cs" />
<Compile Include="Repl.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PlisskenLibrary\PlisskenLibrary.csproj">
<Project>{ebca8a6a-abae-4a43-b43e-672cb9feafad}</Project>
<Name>PlisskenLibrary</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
最后是我的azure管道yml文件
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@0
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
答案 0 :(得分:1)
原来的问题是,我使用.NET Framework创建了控制台应用程序,而不是使用.NET Core控制台应用程序。我用.NET核心应用替换了旧的控制台应用,所有问题都消失了。
从现在开始,直到永远,我将使用dotnet new console
而不是GUI,因为我不太容易犯错误。好时光。
答案 1 :(得分:0)
如何确保以相同的设置还原dotnet项目?
根据您提供的构建日志,您正在使用nuget.exe 4.3.0
来还原软件包。但是,当安装.Net core SDK Nuget.exe 4.3.0
时,2.2.*
似乎已停止正确还原。
因此,要解决此问题,请尝试使用Nuget.exe 4.4.1
。
此外,如果上述方法不能解决该问题,则可以检查以下线程中的答案是否对您有所帮助:
在
TargetLatestRuntimePatch
文件中添加.csproj
属性:<PropertyGroup> <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch> </PropertyGroup>
或
在.csproj文件中设置RuntimeFrameworkVersion和RuntimeIdentifier:
<PropertyGroup> <RuntimeFrameworkVersion>2.1.1</RuntimeFrameworkVersion> <PlatformTarget>AnyCPU</PlatformTarget> <RuntimeIdentifier>win-x64</RuntimeIdentifier> </PropertyGroup>
希望这会有所帮助。