我是 c# 新手,我第一次尝试 Visual Studio Code 是使用命名空间 Microsoft.Toolkit.Uwp.Notifications 中的 ToastContentBuilder 在 Windows 10 上显示通知,这是我的代码:
using Microsoft.Toolkit.Uwp.Notifications;
namespace cs
{
class Program
{
static void Main(string[] args)
{
new ToastContentBuilder ()
.AddArgument("action","hello")
.AddText("my first try in csharp)")
.Show();
}
}
Run Code Online (Sandbox Code Playgroud)
}
这是错误:“ToastContentBuilder”不包含“Show”的定义,并且找不到接受“ToastContentBuilder”类型的第一个参数的可访问扩展方法“Show”(您是否缺少 using 指令或程序集引用? )
我喜欢dotnetCLI 的一点是,您可以运行$ dotnet build --no-incremental,并且始终会获得项目中所有警告的列表。我用它来对项目进行彻底的改变等。其输出可以通过管道传输到 UNIX 工具,以进行进一步处理。
我还想了解您在 Visual Studio 中获得的“建议”。这可能吗?如何实现?
我所说的建议是指您在 Visual Studio 的“错误列表...”中收到的“消息”(见下文)。编译器将此称为“不表明问题的信息”( DiagnosticSeverity.Info),EditorConfig 将此称为这些建议 ( EditorConfigSeverityStrings.Suggestion)。

对此的最小再现是创建一个新的控制台应用程序,并添加一个带有私有字段的新类,但不要这样做readonly(见下文)!这将触发IDE044(如屏幕截图所示),但在运行时不会显示$ dotnet build --no-incremental。如果您通过文件覆盖严重性.editorconfig,那么建议确实会显示,但显然是警告。
public class Class1
{
private string Foo = "bar";
}
Run Code Online (Sandbox Code Playgroud)
.editorconfig[*.cs]
# IDE0044: Add readonly modifier
dotnet_diagnostic.IDE0044.severity = warning
Run Code Online (Sandbox Code Playgroud)
我正在寻找“开箱即用”的东西,比如$ dotnet build .... 但是,如果这是不可能的,我可以使用第 3 方全局工具,例如Roslynator 命令行界面(我确实尝试过该路径,但未能使其正常工作)。
我很清楚您可以在 Roslyn API 之上编写一个自定义工具,但我认为这非常脆弱,因为您需要满足包恢复、查找 …
我在 Azure DevOps 管道中使用 .NET CLI,并使用 PowerShell 解析其输出。我运行的第一个命令是dotnet nuget locals global-packages --list.
第一次运行时的输出如下:
Welcome to .NET 6.0!
---------------------
SDK Version: 6.0.101
Telemetry
---------
The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry
----------------
Installed an ASP.NET …Run Code Online (Sandbox Code Playgroud) 我正在使用 dotnet cli 创建ASP.NET Core Web API
dotnet new webapi --output WebAPI;
Run Code Online (Sandbox Code Playgroud)
是否可以创建它但没有顶级语句?
我正在尝试在我的 Mac(M1 芯片)上安装 .NET 6 和 7,在尝试了多种方法之后,我无处可去。
选项 1:使用brew
/opt/homebrew/Cellar/dotnet/7.0.100就好了。/opt/homebrew/Cellar/dotnet@6/6.0.114当我跑步dotnet --list-runtimes时,我只看到7.0.0。
Microsoft.AspNetCore.App 7.0.0 [/opt/homebrew/Cellar/dotnet/7.0.100/libexec/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.0 [/opt/homebrew/Cellar/dotnet/7.0.100/libexec/shared/Microsoft.NETCore.App]
Run Code Online (Sandbox Code Playgroud)
我知道brew命令创建了dotnet@6.
我怎样才能做到这一点.NET 7以免遇到You must install or update .NET to run this application.错误?
选项 2:使用Install-scripts.
.NET Runtime 6.0.20chmod +x dotnet-install.sh
sudo ./dotnet-install.sh --runtime dotnet --version 6.0.20 --install-dir /opt/homebrew/Cellar/dotnet
sudo ./dotnet-install.sh --runtime …Run Code Online (Sandbox Code Playgroud) 我的目标dotnet-test-mstest": "1.0.1-preview是测试项目中的dotnet核心rc2.
编辑: 好的.我的目标是桌面.NET.但这不应该有任何区别.
project.json
{
"version": "1.0.0-*",
"testRunner": "mstest",
"dependencies": {
"Betgame": "1.0.0-*",
"dotnet-test-mstest": "1.0.1-preview",
"MSTest.TestAdapter": "1.0.0-preview",
"MSTest.TestFramework": "1.0.0-preview",
"NETStandard.Library": "1.5.0-rc2-24027"
},
"frameworks": {
"net461": { }
}
}
Run Code Online (Sandbox Code Playgroud)
运行时输出dotnet test看起来相当不错!
如何将输出作为xml文件在我的构建过程中处理?有任何想法吗?或者它还没有得到支持?
到目前为止我尝试dotnet test -xml test-results.xml但没有生成输出.
我正在尝试使用NancyFX(clint-eastwood)dotnetcore1.1和dotnet-cli 1.0.0-rc4-004771.我目前的项目结构是 -
CustomBootstrapper.cs
HomeModule.cs
index.sshtml
nancyapp.csproj
Program.cs
Startup.cs
Run Code Online (Sandbox Code Playgroud)
代码是 -
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Owin">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Nancy">
<Version>2.0.0-clinteastwood</Version>
</PackageReference>
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
namespace nancyapp
{
class Program
{
static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}
Run Code Online (Sandbox Code Playgroud)
using Microsoft.AspNetCore.Builder;
using Nancy.Owin;
namespace nancyapp
{
public class Startup
{
public …Run Code Online (Sandbox Code Playgroud) 最近,我*.csx使用Visual Studio Studio for Azure Functions将一个使用C#script()的Azure函数转换为预编译的类库.它在Visual Studio 2017中成功构建(以及运行和调试).
我想通过CI流程构建这个AF库.但是,当我在dotnet build本地运行该命令时,它失败并出现以下错误:
C:\ Users\ray\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build \netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5):错误:可能不加载文件或程序集'Microsoft.Azure.WebJobs.Host,Version = 2.1.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'.该系统找不到指定的文件.
我们的CI构建中也会出现相同的错误.
不确定为什么会出现此错误以及如何解决此错误.它是dotnet CLI的版本(我使用的是v1.1)?还有别的吗?
如何获得生成并发布到VSTS中的.NET Core 2.0 xUnit测试报告?
我在我的ASP.NET Core 2.2应用程序上添加了对Docker的支持,并在本地测试Docker的命令时发现了dotnet publish -f netcoreapp2.2 -c Release -o out错误。
./IdentityServer.sln
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer", "IdentityServer\IdentityServer.csproj", "{A435DE31-3D1C-4228-BBD9-0157E849D07D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dependencies", "Dependencies", "{0A7E3F1D-5162-463F-BAF8-714C7FD37B8C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer4", "dependencies\identityserver4\src\IdentityServer4.csproj", "{3A32B19C-B6FC-4A2D-9421-5A16849B7C2A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer4.AspNetIdentity", "dependencies\identityserver4.aspnetidentity\src\IdentityServer4.AspNetIdentity.csproj", "{0E36AE9A-B9B6-4E1C-B446-82A3265432F8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServer.Email", "IdentityServer.Email\IdentityServer.Email.csproj", "{BD699934-C404-4CF4-B77C-511E584D1754}"
EndProject
Run Code Online (Sandbox Code Playgroud)
./IdentityServer/IdentityServer.csproj:https://gist.github.com/paulcsiki/4d3b827af418044dacea0149a2361b81
dotnet restore与解决方案位于同一文件夹中的输出:
Restore completed in 52.96 ms for /Users/paul/docker/dependencies/identityserver4.aspnetidentity/src/IdentityServer4.AspNetIdentity.csproj.
Restore completed in 52.96 ms for /Users/paul/docker/dependencies/identityserver4/src/IdentityServer4.csproj.
Restore completed in 54.56 ms for /Users/paul/docker/IdentityServer/IdentityServer.csproj.
Restore completed in 52.97 ms for /Users/paul/docker/IdentityServer.Email/IdentityServer.Email.csproj.
Run Code Online (Sandbox Code Playgroud)
dotnet publish -f netcoreapp2.2 …
dotnet-cli ×10
c# ×5
.net-core ×4
.net ×3
.net-6.0 ×1
asp.net-core ×1
azure-devops ×1
console ×1
homebrew ×1
macos ×1
mstest ×1
nancy ×1
roslyn ×1
roslynator ×1
xunit ×1