我们Description在dot net CLI中有Enums的属性吗?(Dot Net Core RC2)如果没有,还有其他选择吗?
安装了最新的(我认为).NET Core,通过Visual Studio 2015创建了一个.NET Core Web项目,并尝试开始使用用户机密.CLI声称它丢失了(在声称安装它之后......),如下所示:
E:\Projects\CodeServer>dotnet --version
1.0.0-preview1-002702
E:\Projects\CodeServer>dotnet restore
<snip>
log : Restoring packages for tool 'Microsoft.Extensions.SecretManager.Tools' in E:\Projects\CodeServer\src\CodeServer\project.json...
<snip>
log : Restore completed in 2345ms.
NuGet Config files used:
C:\Users\Work User\AppData\Roaming\NuGet\NuGet.Config
C:\ProgramData\nuget\Config\Microsoft.VisualStudio.Offline.config
Feeds used:
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
E:\Projects\CodeServer>dotnet user-secrets -h
No executable found matching command "dotnet-user-secrets"
E:\Projects\CodeServer>
Run Code Online (Sandbox Code Playgroud)
还要为每个请求添加project.json文件:
{
"userSecretsId": "<snip>",
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview1-final",
"type": …Run Code Online (Sandbox Code Playgroud) 在Visual Studio 2015 Update 3中创建了一个新的ASP.Net核心Web应用程序(.Net Core)项目,并将其签入Visual Studio Team Services git存储库.我正在使用.Net Core和ASP.Net Core的发布版本.
我现在正在尝试使用VSTS Build系统构建它,使用基于本指南的构建定义:https://www.visualstudio.com/en-us/docs/build/apps/aspnet/aspnetcore-to-azure
但是,在dotnet restore下面显示的日志的步骤中构建失败(第一部分未包括在内,这是从它开始失败的地方开始).
我究竟做错了什么?我是否需要以任何方式准备当前的托管代理以使其与ASP.Net Core的v1.0.0版本一起使用?
2016-07-01T06:58:23.7437947Z log : Restoring packages for tool 'BundlerMinifier.Core' in C:\a\1\s\src\FjordTours.BasicApp\project.json...
2016-07-01T06:58:23.7457953Z info : GET https://api.nuget.org/v3-flatcontainer/bundlerminifier.core/index.json
2016-07-01T06:58:24.2167463Z info : OK https://api.nuget.org/v3-flatcontainer/bundlerminifier.core/index.json 469ms
2016-07-01T06:58:24.2188952Z info : GET https://api.nuget.org/v3-flatcontainer/bundlerminifier.core/2.0.238/bundlerminifier.core.2.0.238.nupkg
2016-07-01T06:58:24.4460947Z info : OK https://api.nuget.org/v3-flatcontainer/bundlerminifier.core/2.0.238/bundlerminifier.core.2.0.238.nupkg 226ms
2016-07-01T06:58:24.4500936Z info : GET https://api.nuget.org/v3-flatcontainer/nuglify/index.json
2016-07-01T06:58:24.7169172Z info : OK https://api.nuget.org/v3-flatcontainer/nuglify/index.json 266ms
2016-07-01T06:58:24.7184197Z info : GET https://api.nuget.org/v3-flatcontainer/nuglify/1.5.0/nuglify.1.5.0.nupkg
2016-07-01T06:58:24.9458237Z info : OK https://api.nuget.org/v3-flatcontainer/nuglify/1.5.0/nuglify.1.5.0.nupkg 226ms
2016-07-01T06:58:25.0165432Z log : …Run Code Online (Sandbox Code Playgroud) 我认为,当msbuild即将编译源代码文件,它产生的文件来构建,基于名单Include和Exclude项目的规则.
有没有办法在评估要编译的文件列表之前执行任务?
这是为了能够生成源代码文件并使其在构建中获取.
我正在制作一个.NET Core CLI工具,必须在使用它的项目构建之前运行,因为它(CLI工具)生成一个必须包含在构建中的文件.
该项目是使用新.csproj系统创建的,而不是旧系统project.json.
与我的.NET Core CLI工具项目一起,我创建了一个用于测试目的的库项目.
如果我.csproj在测试库中添加它:
<ItemGroup>
<DotNetCliToolReference Include="MyCliTool" Version="x.x.x" />
<!-- here x.x.x is just a placeholder -->
</ItemGroup>
<Target Name="MyCliToolTarget" AfterTargets="Restore" BeforeTargets="BeforeBuild">
<Exec Command="dotnet my-cli-tool" />
</Target>
Run Code Online (Sandbox Code Playgroud)
然后,如果之前不存在,则不会在编译中考虑CLI工具生成的文件.这意味着当文件存在时,它可以,但这也意味着第一次构建(克隆,清理或什么之后)总是会失败.
我尝试了几个不同的目标,BeforeTargets但我找不到让它工作的方法.我试图InitialTargets在Project节点中设置我的目标,但它也不起作用.我试图Outputs将Target节点的属性设置为CLI工具生成的文件名,但同样,它失败了.
我发现唯一有效的解决方案是手动添加Compile指令,如下所示:
<ItemGroup>
<Compile Include="MyGeneratedFile.cs" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
此解决方案暂时没问题,但文件名可能会根据CLI工具选项而改变,这会使两个地方的文件名必须在更改时更新,如下所示:
<ItemGroup>
<Compile Include="PATH\TO\CUSTOM_FILENAME_HERE.CS" />
<DotNetCliToolReference Include="MyCliTool" Version="x.x.x" />
</ItemGroup>
<Target Name="MyCliToolTarget" …Run Code Online (Sandbox Code Playgroud) 我在开发过程中运行这样的网络项目:
dotnet watch run
Run Code Online (Sandbox Code Playgroud)
当我进行更改时,项目/浏览器会重新加载。惊人的!
但是,有时我会看到这样的内容:
Unable to apply hot reload because of a rude edit.
Do you want to restart your app - Yes (y) / No (n) / Always (a) / Never (v)?
Run Code Online (Sandbox Code Playgroud)
我可以在命令行中添加一些内容,以便强制使用“Always (a)”选项吗?
像这样的东西:
dotnet watch run --AlwaysRestartOnRudeEdit
Run Code Online (Sandbox Code Playgroud)
根据我的 google-fu/duckduck-fu,这样的选项不存在 - 但我希望它得到确认。:)
我们安装了三个版本的dotnet命令行界面:
C:\Program Files\dotnet\sdk> dir -name
1.0.0-preview2-003133
1.0.0-preview2-1-003177
1.0.0-preview3-004056
Run Code Online (Sandbox Code Playgroud)
我们如何选择在运行时使用哪个版本dotnet restore?现在版本始终是preview3构建版本.
我们的PATH C:\Program Files\dotnet\包含:
host
sdk
shared
swidtag
dotnet.exe
LICENSE.txt
ThirdPartyNotices.txt
Run Code Online (Sandbox Code Playgroud)
我们如何选择dotnet.exe使用哪种SDK ?
当我尝试Microsoft.AspNetCore.AppRef在 .net core 3.1 中安装我的网络应用程序时。
但是,我收到此错误:
Package 'Microsoft.AspNetCore.App.Ref 3.1.3' has a package type 'DotnetPlatform' that is not supported by project 'xxxxxx'.
NU1213 The package Microsoft.AspNetCore.App.Ref 3.1.3 has a package type DotnetPlatform that is incompatible with this project.
Run Code Online (Sandbox Code Playgroud)
有什么想法如何修复吗?
最后是一种从命令行执行c#脚本文件的简单方法吗?
根据这个线程,我认为dotnet run Test.cs应该做的工作.
但对于我的测试类,它是:
using System;
namespace Scripts
{
public class Program
{
public static void Main(string[] args)
{
Console.Out.WriteLine("This is the miracle");
}
}
}
Run Code Online (Sandbox Code Playgroud)
它失败
PM> dotnet run .\Test.cs
dotnet.exe : Object reference not set to an instance of an object.At line:1 char:1
Run Code Online (Sandbox Code Playgroud)
那么如何使用命令行以相对简单的方式在单个文件中执行代码呢?
UPD 1:@Lee和@svick正确提到的dotnet run是运行项目.但我最初的问题是 - 如何运行单个文件.也许有些选择使用roslyn?
我创建了一个针对两个框架(.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) dotnet-cli ×10
.net-core ×5
.net ×3
asp.net-core ×2
c# ×2
msbuild ×2
nuget ×2
.net-6.0 ×1
azure-devops ×1
dotnet-watch ×1
project.json ×1
roslyn ×1
task ×1