有没有办法如何使用面向 .netstandard2.0 的辅助角色运行 Azure 云服务经典项目?
我有这样的项目,但是任何时候我尝试构建它时都会收到此错误:
严重性代码描述项目文件行抑制状态错误项目“C:\path\to\project\src\Frontend\Frontend.csproj”目标“.NETStandard,Version=v2.0”。它不能被以“.NETFramework,Version=v4.0”为目标的项目引用。UserDiscoveryService C:\Program Files\dotnet\sdk\2.0.2\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.Common.targets 87
我试图在 ccproj 中设置目标框架,但它没有帮助我。
我在 Framework 4.7.2 中有我的主要项目,这个项目引用了一个 netStandard Library 项目,它是一个 netstandard 2.0。
我需要 .Net Standard 项目中的“DbProviderFactories”。
喜欢:
System.Data.Common.DbProviderFactory fact = System.Data.Common.DbProviderFactories.GetFactory(providername);
Run Code Online (Sandbox Code Playgroud)
我可以将 netStandard Project 版本更改为 2.1,其中包含 DbProviderFactories,但 netstandard 2.1 不使用框架 4.7.2
有没有其他方法可以做到这一点。
我正在尝试构建一个ASP.NET-Core 3.1
( netcoreapp3.1
) 应用程序,该应用程序依赖于.NET-Standard 2.0
使用 MSBuild SDK的 NuGet 库"Microsoft.NET.Sdk.Razor"
。
这在 Visual Studio (2019) 中构建并运行良好,但是当我运行时dotnet build
出现以下错误:
Build FAILED.
CSC : error CS8034: Unable to load Analyzer assembly
C:\Users\daniel\.nuget\packages\microsoft.aspnetcore.mvc.analyzers\2.2.0\analyzers\dotnet\cs\Microsoft.AspNetCore.Mvc.Analyzers.dll
: Assembly with same name is already loaded [D:\git\myapp\src\myapp.App\myapp.App.csproj]
0 Warning(s)
1 Error(s)
Run Code Online (Sandbox Code Playgroud)
我的猜测是我的.NET-Standard 2.0
库正在Microsoft.CodeQuality.Analyzers
通过Microsoft.NET.Sdk.Razor
SDK拉入2.x ,这与ASP.NET-Core 3.1
应用程序拉入的库相冲突。
有没有一种方法可以像 Visual Studio 一样通过命令行构建我的应用程序?
#if NETCOREAPP3_1
在我的库中使用多目标和块的正确解决方案是什么?
c# .net-core asp.net-core .net-standard-2.0 asp.net-core-3.1
我无法使Microsoft.EntityFrameworkCore 2.0与NETStandard.Library 2.0一起使用
错误CS0433类型'AttributeUsageAttribute'在'System.Runtime,Version = 4.1.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'和'netstandard,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = cc7b13ffcd2ddd51'中都存在。架构D:\ Contrived \ Contrived \ Framework \ Contrived.Model.Schema \ Attributes \ EntityColumnAttribute.cs
我的.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="NETStandard.Library" Version="2.0.0" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
如果我创建一个新的解决方案和一个netstandard 2.0库,然后添加EntityFrameworkCore 2.0,也会发生这种情况
错误CS1703已导入具有相同标识的多个程序集:'D:\ Users \ maksymiuk_a.nuget \ packages \ netstandard.library \ 2.0.0 \ build \ netstandard2.0 \ ref \ System.Threading.Tasks.dll'和'D :\ Users \ maksymiuk_a.nuget \ packages …
我在Visual Studio 2015中有一个很好的旧.NET Framework 4.7 类库,目前使用的是NuGet软件包版本1.1.2.我正在尝试将此更新到2.0版,但我收到此错误: Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration 2.0.0'.您正在尝试将此软件包安装到以".NETFramework,Version = v4.7"为目标的项目中,但该软件包不包含任何与该框架兼容的程序集引用或内容文件.有关更多信息,请与软件包作者联系.
我看到新版本仅支持.NETStandard 2.0.我是否必须在Visual Studio 2017中将所有项目转换为.NET Core或.NET Standard?
有人知道是否有任何方法可以将AutoMapper与ASP.Net Core 2.0一起使用?IServiceCollection没有扩展名.
可选问题,是否有人尝试使用.Net Framework 4.7或.Net Standard 2.0的AutoMapper?
由于我需要导入一个面向.NET Standard 2的库,我已经将我的库升级到了.NET 4.7.1,正如我从MS视频中所理解的那样应该避免这个问题:https://www.youtube.com/watch? v = u67Eu_IgEMs
但是,添加.NET标准现在会导致数十个System.xxx引用,而不是对.NET Standard的单个引用(根据视频).
更糟糕的是,已经添加了几个引用但是底层文件似乎缺少生成警告,例如
我甚至在视频中重新创建了演示项目并得到了相同的结果 - 没有单一的.NET Standard引用,大量的DLL引用代替.
Warning The referenced component 'Microsoft.Win32.Primitives' could not be found.
Warning The referenced component 'System.IO.FileSystem' could not be found.
Warning The referenced component 'System.Security.Cryptography.X509Certificates' could not be found.
Warning The referenced component 'System.Globalization.Calendars' could not be found.
Warning The referenced component 'System.Security.Cryptography.Encoding' could not be found.
Warning The referenced component 'System.Security.Cryptography.Primitives' could not be found.
Warning The referenced component 'System.IO.Compression.ZipFile' could not be found. …
尝试编译此代码示例:
var c = new CSharpCodeProvider();
var cp = new CompilerParameters();
var className = $"CodeEvaler_{Guid.NewGuid().ToString("N")}";
// doesn't work with or without netstandard reference
var netstandard = Assembly.Load("netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51");
cp.ReferencedAssemblies.Add(netstandard.Location);
cp.CompilerOptions = "/t:library";
cp.GenerateInMemory = true;
var sb = new StringBuilder("");
sb.Append("namespace Jobs.Dynamic{ \n");
sb.Append($"public class {className} {{\n");
sb.Append($"public object RunSnippetCode()\n{{\n");
sb.Append("\nreturn null;\n");
sb.Append("\n}\n");
sb.Append("}");
sb.Append("}");
CompilerResults cr = c.CompileAssemblyFromSource(cp, sb.ToString());
Run Code Online (Sandbox Code Playgroud)
在.netstandard 2.0上进行迁移之前,一切正常
必须生成一个简单的类,并且只要复制代码并在Visual Studio中运行它,它就可以工作。具有一个返回null的方法的类。现在,CompileAssemblyFromSource方法将引发
System.PlatformNotSupportedException:该平台不支持该操作。在Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options,String [] fileNames)在Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters选项,String []源)在CnetContent.Jobs.Dyn。 ctor(IEnumerable
1 referencedAssemblies, IEnumerable
1 usings,String methodArgs,String codeSnippet)在CnetContent.Jobs.Core.JobBase.EvalRunCondition(String&错误)
我更新了System.CodeDom,并且此库支持.netstandard …
我有多个程序集,其中包括单个 .NET Standard 2.0 项目的单元测试。为了彻底测试我的项目,我希望内部类对两个程序集都可见。
这是我的文件的一部分.csproj
,它使内部结构对一个程序集可见:
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>$(MSBuildProjectName).Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
如何向此配置添加其他程序集?
现在它适用于我需要的两个值之一,但我还没有弄清楚如何让它同时适用于这两个值。这应该是可能的,因为我在 .NET 和 .NET Framework 中找到了解决方案,但在 .NET Standard 中没有找到。
有什么建议么?
我有一个 .NET Standard 2.0 DLL 项目。
它没有其他参考,除了NETStandard.Library 2.0.1
一切都很好。
它被 WPF 应用程序引用,一切似乎都正常。
将 nuget 包添加System.Collections.Immutable 1.5.0
到 DLL 项目后,Dependencies
解决方案资源管理器的根目录上会出现一个黄色感叹号。(嗯......我现在看到即使在我删除这个包后感叹号仍然存在,但我想这是一个 VS 错误,因为在添加这个库之前一切似乎都很好)
拥有这两个包,一切都很好,但是当我尝试使用 时ImmutableDictionary
,我得到了这个:
System.IO.FileNotFoundException: '无法加载文件或程序集 'System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其依赖项之一。该系统找不到指定的文件。'
查看 nuget 包,我明白这两个应该一起工作,因为(根据我的理解)'System.Collections.Immutable` 库说它支持 .NET 标准 2.0。
我对 .NET Standard 世界很陌生。
查看System.Collections.Immutable.dll
我的主应用程序bin
文件夹中的公钥令牌,我发现它确实b03f5f7f11d50a3a
如预期的那样。不过版本不一样。
通常,在旧的 .NET 中,我会尝试在应用程序的配置文件中添加程序集重定向。但在这里这样做似乎没有任何区别。将此添加到我引用 DLL 的 WPF 应用程序中:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)
...将异常更改为:
System.IO.FileNotFoundException: '无法加载文件或程序集 …
.net c# .net-assembly assembly-binding-redirect .net-standard-2.0
c# ×10
.net ×5
.net-core ×2
asp.net-core ×2
.net-4.7 ×1
automapper ×1
azure ×1
codedom ×1
csproj ×1
internals ×1