我在恢复ASP.NET 5/ASP.NET Core 1.0的依赖项时遇到错误.
似乎有几个依赖项(即Microsoft.CodeAnalysis.CSharp/ .Common)Microsoft.AspNet.Mvc被修复为看似过时的软件包.
对此的要求是使用dotnetcli工具并以.NET Vanilla和.NET Core为目标.
有没有办法让Mvc引用Core兼容的CodeAnalysis版本?
在Visual Studio 2015中重现的步骤(v14.0.24729.00 Update 1):
dotnet restore输出:
info : Restoring packages for C:\PATH_TO_SOLUTION\WebApplication2\src\WebApplication2\project.json...
error: Microsoft.CodeAnalysis.CSharp 1.1.0-rc1-20151109-01 is not compatible with DNXCore,Version=v5.0.
error: Microsoft.CodeAnalysis.Common 1.1.0-rc1-20151109-01 is not compatible with DNXCore,Version=v5.0.
error: Some packages are not compatible with DNXCore,Version=v5.0.
error: Microsoft.CodeAnalysis.CSharp 1.1.0-rc1-20151109-01 is not compatible with DNXCore,Version=v5.0 (win7-x64).
error: Microsoft.CodeAnalysis.Common 1.1.0-rc1-20151109-01 is not compatible with …Run Code Online (Sandbox Code Playgroud) 我创建了一个针对两个框架(.net core 2.2 和 .net core 3.0)并使用目标框架符号(NETCOREAPP2_2 和 NETCOREAPP3_0)的小型应用程序。
项目文件非常简单,如下所示:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;netcoreapp2.2</TargetFrameworks>
<OutputType>Exe</OutputType>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
程序代码可能再简单不过了:
public class MyClass
{
static void Main()
{
#if NETCOREAPP3_0
System.Console.WriteLine("Target framework: NETCOREAPP3_0");
#elif NETCOREAPP2_2
System.Console.WriteLine("Target framework: NETCOREAPP2_2");
#else
System.Console.WriteLine("Target framework: WHO KNOWS?!");
#endif
#if TEST_RUN
System.Console.WriteLine("Test mode active!");
#endif
}
}
Run Code Online (Sandbox Code Playgroud)
如果我使用常规命令而不带附加参数构建它dotnet build --no-incremental,则两个版本都会创建并按预期工作:
PS>> dotnet .\bin\Debug\netcoreapp2.2\TargetFramework.dll
Target framework: NETCOREAPP2_2
PS>> dotnet .\bin\Debug\netcoreapp3.0\TargetFramework.dll
Target framework: NETCOREAPP3_0
Run Code Online (Sandbox Code Playgroud)
在我的场景中,我需要使用附加编译符号构建两个版本TEST_RUN。所以我在构建命令中添加了额外的参数dotnet build --no-incremental -p:DefineConstants=TEST_RUN。结果我有一个应用程序,但不知道目标框架:
PS>> dotnet .\bin\Debug\netcoreapp2.2\TargetFramework.dll
Target framework: …Run Code Online (Sandbox Code Playgroud) 我正在使用dotnet pack命令为以下场景创建 NuGet 包:
项目结构:
Project B
|----> Project A
Project A
|----> SomePackage
Run Code Online (Sandbox Code Playgroud)
我想创建一个包含ProjectB.dll、ProjectA.dll和SomePackage作为 NuGet 包依赖项的 NuGet 包。
为了包含为 NuGet 包(而不是包依赖项)的一部分,我使用了此处ProjectA.dll建议的以下解决方案。
在ProjectB.csproj:
<ProjectReference Include="ProjectA.csproj" PrivateAssets="all"/>
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="BuildOnlySettings;ResolveReferences">
<ItemGroup>
<!-- Filter out unnecessary files -->
<_ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'All'))"/>
</ItemGroup>
<!-- Print batches for debug purposes -->
<Message Text="Batch for .nupkg: ReferenceCopyLocalPaths = @(_ReferenceCopyLocalPaths), ReferenceCopyLocalPaths.DestinationSubDirectory = %(_ReferenceCopyLocalPaths.DestinationSubDirectory) Filename = %(_ReferenceCopyLocalPaths.Filename) Extension = %(_ReferenceCopyLocalPaths.Extension)" …Run Code Online (Sandbox Code Playgroud) 我想在发布之前清理我的外部输出文件夹。我今天得到的解决方案如下:
Remove-Item -Path ..\artifacts -ErrorAction SilentlyContinue -Recurse -Force;
dotnet publish ..\myproject.sln -c Release -o ..\artifacts\myproject;
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来做到这一点(没有Remove-Item)?我尝试使用dotnet clean并指定输出文件夹,但不起作用。
使用visual studio发布我的asp核心项目时,.config会在我的可执行文件旁边创建一个文件.
在.config包括几个bindingRedirect这样的:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="6.0.0.0" newVersion="8.0.0.0" />
<bindingRedirect oldVersion="7.0.0.0" newVersion="8.0.0.0" />
<bindingRedirect oldVersion="6.0.0.0" newVersion="9.0.0.0" />
<bindingRedirect oldVersion="8.0.0.0" newVersion="9.0.0.0" />
<bindingRedirect oldVersion="7.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Serilog" publicKeyToken="24c2f752a8e58a10" culture="neutral" />
<bindingRedirect oldVersion="1.5.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="1.1.37.0" newVersion="1.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="1.2.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在这里,我想将 …
我有一个项目有一个
[TestFixture, Category("Oracle")]
Run Code Online (Sandbox Code Playgroud)
和a
[TestFixture, Category("OracleOdbc")]
Run Code Online (Sandbox Code Playgroud)
一对夫妇的测试,我想执行分开使用dotnet test.
这是我在一些谷歌搜索后尝试的:
dotnet test MyProject.csproj --where "cat==Oracle" 但是这个开关不再存在了.dotnet test MyProject.csproj --filter Category="Oracle"产生0适用的测试:No test is available in ....然后,我偶然发现了这篇文章,虽然它描述了MSTest(和NUnit有CategoryAttribute而不是a TestCategoryAttribute),我试过了
dotnet test MyProject.csproj --filter TestCategory="Oracle"答对了.这次所有"Oracle"测试都已执行.但现在是令人困惑的部分.如果我运行dotnet test MyProject.csproj --filter TestCategory="OracleOdbc",所有测试都在执行,包括"Oracle" 和 "OracleOdbc".这让我想知道是否TestCategroy是NUnit的正确方法,或者这是一个错误.
我正在使用.NET命令行工具(2.1.2),项目参考是:
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="NUnit" Version="3.8.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.7" />
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我不知道这是否重要,但我的测试项目是多目标netcoreapp2.0和net462.
我们有一个使用DbContextfrom 的简单netcore 2.2控制台应用程序Microsoft.EntityFrameworkCore。从控制台启动后,它可以按预期工作。
但是,我们决定将其用作dotnet CLI工具。.csproj文件包含:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AssemblyName>dotnet-dbupdate</AssemblyName>
<Title>Db Updater</Title>
<Version>1.0.1</Version>
<PackageId>DbUpdater</PackageId>
<Product>DbUpdater</Product>
<PackageVersion>1.0.1</PackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我们使用将其打包到我们的Nuget服务器dotnet pack。然后在目标文件夹中,有以下.csproj文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="DbUpdater" Version="1.0.1" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
从此文件夹中,将其还原并执行:
dotnet restore
dotnet dbupdate
Run Code Online (Sandbox Code Playgroud)
突然之间,在DbSet的ToList方法调用中,我们收到:
System.Data.SqlClient is not supported on this platform
Run Code Online (Sandbox Code Playgroud)
毫无疑问,将其作为dotnet CLI工具启动时存在问题。但是,我们仍然没有得到这个问题的含义和解决方法。在网络上搜索并没有给我们任何尝试的思路。
尝试使用 .NET Core CLI 任务 (DotNetCoreCLI@2) 抑制 Azure DevOps 管道中的警告,但出现以下错误:
MSBUILD:错误 MSB1001:未知开关。开关:--noWarn:MSB3277
以下是代码示例,类似于我在与 msbuild cli 参考相关的几篇文章中使用开关的方式:
- task: DotNetCoreCLI@2
displayName: Release Build
inputs:
command: 'build'
projects: '${{ parameters.solutionPath }}'
arguments: --configuration Release --noWarn:MSB3277
Run Code Online (Sandbox Code Playgroud)
我也尝试过小写 --nowarn ,但仍然没有运气,所以任何有关此问题的帮助将不胜感激。
预先感谢您的支持,
特里
我是 c# 新手,我正在尝试将包添加到我的项目中,我之前尝试通过 dotnet cli 添加“Microsoft.Toolkit.Uwp.Notifications” dotnet add package Microsoft.Toolkit.Uwp.Notifications,然后尝试模仿 Microsoft 示例Microsoft.Docs 但它总是显示此错误,有什么帮助吗?
info :将包“Newtonsoft.Json”的 PackageReference 添加到项目“C:\Users\moham\cs\cs.csproj”中。错误:“Newtonsoft.Json”包没有可用的版本。
当我尝试时dotnet add package Newtonsoft.Json --version 13.0.1出现此错误:CMD 错误
dotnet-cli ×10
.net-core ×6
c# ×5
asp.net-core ×2
asp.net-mvc ×1
azure-devops ×1
cmd ×1
msbuild ×1
nuget ×1
nunit ×1
package ×1