我的文件夹/目录中已经有一个Program.cs,没有其他文件。
当我这样做时dotnet new console,它不会让我创建它,除非我使用--force覆盖Program.cs. 我想我只需要创建.csproj项目文件来构建、运行和调试它。
有没有dotnet new console跳过Program.cs创建的选项?
否则,我将需要创建一个新目录并创建dotnet new console,然后我必须将自动生成的目录替换Program.cs为我的Program.cs.
我希望从多个 .csproj 创建一个 nuget 包。
例如:我有两个 .csproj,其中之一依赖于其他外部包,例如 NewtonSoft。
dotnet new classlib -o ClassLibrary1
dotnet new classlib -o ClassLibrary2
cd ClassLibrary1
dotnet add package Newtonsoft.Json
Run Code Online (Sandbox Code Playgroud)
我希望发布一个包含 ClassLibrary1.dll 和 ClassLibrary2.dll 的单个 nuget 包,并且生成的 .nuspec 列出了依赖项 Newtonsoft.Json。
我尝试做这样的事情:创建了一个虚拟 .csproj 并添加了对 ClassLibrary1 & 2 的引用,并使用 -IncludeReferencedProjects: Ex:- 创建了一个 nuget 包
dotnet new classlib -o dummyNuget
dotnet add reference ClassLibrary1.csproj
dotnet add reference ClassLibrary2.csproj
nuget pack dummyNuget.csproj -IncludeReferencedProjects
Run Code Online (Sandbox Code Playgroud)
它生成以下 .nuspec 文件,缺少 NewtonSoft 依赖项。
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>dummynuget</id>
<version>1.0.0</version>
<authors></authors>
<description>Description</description>
<dependencies /> …Run Code Online (Sandbox Code Playgroud) 使用时dotnet new webapi -n API,它会生成带有properties、obj和bin子文件夹的 API 文件夹,如下面的屏幕截图所示,但它没有Controllers文件夹。有人可以指导我吗?该项目使用.NET 8.0
一直在努力让这个工作,我有一个标准的.NET Core API,我想在远程IIS服务器上托管,问题是大多数教程是针对ASP.NET 5/vNext并且不解释会发生什么一旦你运行你的dotnet publish.我的绑定是正确的,但我不确定我是否指向正确的文件夹.
在我的输出文件夹中,我有发布和wwwroot以及config.json一些其他json文件.当我将IIS指向wwwroot文件夹时,我得到:
502 - Web服务器在充当网关或代理服务器时收到无效响应.
如果我尝试将其指向任何其他文件夹,我会得到404s.我安装了HttpPlatformHandler 1.2.我的project.json情况如下:
{
"compilationOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot"
]
},
"dependencies": {
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-*",
"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0-*",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-*",
"Microsoft.AspNetCore.Hosting": "1.0.0-*",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-*",
"Microsoft.AspNetCore.IISPlatformHandler": "1.0.0-*",
"Microsoft.AspNetCore.Mvc": "1.0.0-*",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-*",
"Microsoft.Extensions.Configuration.Json": "1.0.0-*",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-*",
"Microsoft.Extensions.Logging.Debug": "1.0.0-*",
"OpenIddict.Core": "1.0.0-*",
"OpenIddict.EF": "1.0.0-*",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002700" …Run Code Online (Sandbox Code Playgroud) 我想使用.NET Core 创建一个自包含的 Web应用程序.我想针对任何版本的Windows,并在我的project.json:
"runtimes": {
"win10-x64": { },
"win8-x64": { },
"win7-x64": { }
}
Run Code Online (Sandbox Code Playgroud)
当我运行时,dotnet publish --runtime win10-x64我只能指定一次发布一个运行时.然后我必须保留三份二进制文件.
是否可以为所有三个运行时发布我的应用程序并将该文件夹复制为完全独立的应用程序?
我一直在玩通过创建的项目
dotnet new Angular.
Run Code Online (Sandbox Code Playgroud)
我喜欢它!
但我需要从我的项目中引用一个.net 4.6.1项目.我的第一个想法是将Angular项目改为.net 4.6.1项目,因为一个461项目显然可以引用另一个项目.所以我尝试更改.csproj文件,替换
<TargetFramework>netcoreapp2.0</TargetFramework>
Run Code Online (Sandbox Code Playgroud)
同
<TargetFramework>net461</TargetFramework>.
Run Code Online (Sandbox Code Playgroud)
但后来我得到了一堆构建错误,从以下开始:
Package Microsoft.AspNetCore.All 2.0.0 is not compatible with net461 (.NETFramework,Version=v4.6.1) / win7-x86. Package Microsoft.AspNetCore.All 2.0.0 supports: netcoreapp2.0 (.NETCoreApp,Version=v2.0) Angular C:\Code\Learning\angular\foo\AngularTest\Angular\Angular.csproj 1
Run Code Online (Sandbox Code Playgroud)
如果我删除对Microsoft.AspNetCore.All的引用,我从代码中得到错误,说明缺少Microsoft.AspNetCore.All.
我没有问题之前使用过Angular和.net 4.6.1.所以应该有办法做到这一点.但它是什么?
我喜欢在我的 CICD 管道中为 NuGet 包使用内部版本号或其他一些计算出的版本号。本质上,我喜欢开发人员控制主要和次要版本号,但会自动增加构建。
有了nuget.exe我可以使用-Version开关来覆盖最终包中的版本。但是,对于 .NET Core 2.0 库项目,这失败了,我必须使用dotnet pack,请参阅:
https://github.com/NuGet/Home/issues/4491
这只是一个--version-prefixCLI 参数,dotnet pack所以我如何完全覆盖版本?
启动一个新项目,并尝试设置数据库进行身份验证。我在 powershell 中运行以下命令。
dotnet ef database update -Context ApplicationDbContext
并得到以下错误Unrecognized option '-Context'
所以我尝试在不使用 -Context 选项的情况下运行它,只是为了查看和获取:
More than one DbContext was found. Specify which one to use. Use the '-Context' parameter
for PowerShell commands and the '--context' parameter for dotnet commands.
Run Code Online (Sandbox Code Playgroud)
我还尝试使用 --context 而不是 -context 运行它,但得到相同的错误。关于为什么它认识到我需要该选项,但同时又告诉我它不认识该选项,有什么建议吗?
我还重新启动了powershell。
我已将 NuGet 包 (BuildingBlocks) 发布到 Github Packages。我使用 nuget.config 文件指定项目的 nuget 源以及包的凭据(故意用占位符替换凭据):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="github" value="https://nuget.pkg.github.com/<username>/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="<username>" />
<add key="ClearTextPassword" value="<password>" />
</github>
</packageSourceCredentials>
</configuration>
Run Code Online (Sandbox Code Playgroud)
当我在 Fedora 机器上本地运行 dotnet Restore 时,它工作正常。但是,当我尝试恢复从mcr.microsoft.com/dotnet/sdk映像派生的 Docker 容器中的包时,恢复失败并出现以下错误:
Determining projects to restore...
/app/src/DocumentService.Application/DocumentService.Application.csproj : error NU1101: Unable to find package BuildingBlocks.Annotations. No packages exist with …Run Code Online (Sandbox Code Playgroud) nuget nuget-package-restore .net-core asp.net-core dotnet-cli
重现步骤
dotnet new console
(introduce a bug in Program.cs)
dotnet restore
dotnet build
Run Code Online (Sandbox Code Playgroud)
典型的输出为:
Microsoft (R) Build Engine version 15.1.548.43366 Copyright (C) Microsoft Corporation. All rights reserved.
Program.cs(5,5): error CS0116: A namespace cannot directly contain members such as fields or methods [/Users/xxx/Documents/myproj/myproj.csproj]
Build FAILED.
Program.cs(5,5): error CS0116: A namespace cannot directly contain members such as fields or methods [/Users/xxx/Documents/myproj/myproj.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.77
Run Code Online (Sandbox Code Playgroud)
您可以看到错误CS0116被报告两次。
我的问题是:有没有办法避免重复报告错误?
我删除了 Visual Studio,但我喜欢 c#。我从dotnet 官方网站下载了 dotnet并安装了它。然后我写在命令行dotnet new console和所有工作,dotnet run工作。然后我创建其他文件夹并在那里写入dotnet new classlib(是 .dll)并且它工作。但我不知道如何将我的 .dll 文件添加到我的项目中。怎么做?
我使用dotnet cli创建了一个项目,一切正常,直到我想为应用程序编写测试.
我创建了一个src目录并将整个Web项目移动到该src文件夹,之后我在一个名为的文件夹中创建了测试项目tests.
我在测试项目中添加了对Web应用程序的引用,测试成功运行但是当我运行我的应用程序时,dotnet run我收到以下错误:
该
Views文件夹位于src目录中,其他所有文件都包含*.csproj.
请在下面找到我的文件夹结构:
任何帮助,将不胜感激.谢谢.
dotnet-cli ×12
.net-core ×7
c# ×4
asp.net-core ×3
nuget ×3
msbuild ×2
.net ×1
.net-6.0 ×1
.net-8.0 ×1
angular ×1
asp.net ×1
dotnet-new ×1
iis ×1
project.json ×1