我正在尝试深入研究 ASP.NET Core。因此,我决定尝试使用 VS Code 创建一个宠物项目。
在 dotnet cmd 的帮助下,我创建了一个解决方案,向其中添加了项目(应用程序、测试、EF、映射等)并在项目之间设置引用。
但现在,当我尝试运行该解决方案时,我收到了Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute
错误和一堆其他奇怪的错误。这是我收到的错误的一部分:
c:\Projects\dotNet\BestTongue\Utilities\objBinRemove\obj\Debug\netcoreapp3.0\objBinRemove.AssemblyInfo.cs(10,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [C:\Projects\dotNet\BestTongue\BestTongue.csproj]
c:\Projects\dotNet\BestTongue\Utilities\objBinRemove\obj\Debug\netcoreapp3.0\objBinRemove.AssemblyInfo.cs(11,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [C:\Projects\dotNet\BestTongue\BestTongue.csproj]
...
Run Code Online (Sandbox Code Playgroud)
我不确定我还需要在问题中添加什么才能解决问题。因此,如果我遗漏了某些内容,请在评论中询问所有必要的详细信息。
我花了很多时间试图找到问题的解决方案,但徒劳无功。
更新
正如评论部分所建议的那样,我尝试使用相关问题中提到的解决方案。
我尝试添加:
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
所以,现在我的.csproj
样子是这样的:
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\App\App.csproj" />
<ProjectReference Include="..\Data\Data.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>netstandard3.0</TargetFramework>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
但我仍然看到同样的错误:
另外,我编写了一个脚本来遍历所有项目并删除*.AssemblyInfo.cs
. 之后我检查了建设项目是否会带回来*.AssemblyInfo.cs
。并且*.AssemblyInfo.cs
在构建后再次出现。另外,现在(.csproj
文件修改后)我收到了一个新错误:
C:\Program …
VS Code 中的 Omnisharp 会产生很多关于 Unity 项目的警告。为什么?
当我从 Unity 编辑器在 VS Code 中打开脚本时,我看到的是:
Omnisharp 发出警告。这里有几个:
[warn]: OmniSharp.MSBuild.ProjectLoader
The referenced project 'Unity.Timeline.Editor.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
The referenced project 'Unity.VSCode.Editor.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
The referenced project 'Unity.TextMeshPro.Editor.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
The referenced project 'UnityEngine.UI.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
The referenced project 'Unity.Timeline.csproj' does not exist.
[warn]: OmniSharp.MSBuild.ProjectLoader
...
[warn]: OmniSharp.MSBuild.ProjectManager
Expected project reference c:\Projects\Unity\Combo Bombo\Unity.2D.Sprite.Editor.csproj to be already loaded for project Assembly-CSharp
[warn]: OmniSharp.MSBuild.ProjectManager
Expected …
Run Code Online (Sandbox Code Playgroud) ASP.NET Core 中控制器路由中的方括号是什么意思?
例如Route("[controller]")在这里:
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
...
}
Run Code Online (Sandbox Code Playgroud) 如何在 VS Code 中启用 Node.js Intellisense?
例如,我知道 Node.js 中有一个常量__dirname
,但是当我尝试输入__dir
VS Code 时,我没有得到任何建议,而我希望将其__dirname
视为建议。
我该怎么办?也许我应该安装一个插件?
这是我正在使用的 VS Code 版本:
Version: 1.33.1 (user setup)
Commit: 51b0b28134d51361cf996d2f0a1c698247aeabd8
Date: 2019-04-11T08:27:14.102Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.17763
Run Code Online (Sandbox Code Playgroud)
谢谢你。
Unity 开发人员如何限制从 Object 派生的泛型类型参数?
在寻找问题的答案时,我遇到了这个问题。有答案说明以下内容:
这两个约束之间没有区别,除了一个是不允许明确声明的。
证明应该不可能约束对象。在 Unity 中,我们可以看到以下方法:
public static T Instantiate<T>(T original, Vector3 position, Quaternion rotation) where T : Object;
Run Code Online (Sandbox Code Playgroud)
这是因为 Unity 使用的是 Mono 而不是 CLR 吗?
哪里有活动文档同步在Visual Studio中的按钮?
我知道我可以按Alt
+ Shift
+L
并且我将获得与活动文档的同步。我也知道每次我关注另一个文件时,我都可以在“选项”中启用该功能。
但是我在 VS 界面中找不到按钮来做到这一点。它甚至存在吗?我希望这样的按钮位于 VS 界面的顶部。在评论/取消评论按钮附近的某个地方(这只是我觉得它在那里,我没有证据或理由这么认为)。
如果字符串是在 C# 中插入的,如何检查接受字符串的方法内部?
// String interpolation
var author = db.Authors.FromSql($"SELECT * From Authors Where AuthorId = {id}").FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
如果内联提供给 FromSql 方法调用,Entity Framework Core 只会参数化内插字符串。在 FromSql 方法调用之外声明的内插字符串将不会被解析为参数占位符。实际上,您将直接将串联字符串传递给数据库,这存在 SQL 注入风险。
以下示例是危险的,不应使用:
var sql = $"SELECT * From Authors Where AuthorId = {id}";
var author = db.Authors.FromSql(sql).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
在阅读上面的摘录之前,我认为在一个方法中我得到了一个字符串并且不可能知道它是如何构造的。摘录让我相信这在某种程度上是可能的。
.NET 中程序集的标记类型是什么?
我正在通过教程学习 AutoMapper,我marker types for assemblies
在这里遇到了over的概念:
// Or marker types for assemblies:
var configuration = new MapperConfiguration(cfg =>
cfg.AddMaps(new [] {
typeof(HomeController),
typeof(Entity)
});
);
Run Code Online (Sandbox Code Playgroud)
在寻找我的问题的答案时,我遇到了这个问题。但我无法在那里找到答案。
很长一段时间,我认为它可以让我释放finally
块中的所有资源,并且我认为如果try
块中发生异常,那么该块中的资源仍然会被释放finally
。但情况似乎并非如此。
我有以下一段代码:
using System;
public sealed class Program
{
public static void Main()
{
try {
int zero = 0;
int i = 1/zero;
} finally {
Console.WriteLine("divide by zero"); //the line is never called
}
}
}
Run Code Online (Sandbox Code Playgroud)
我从来没有到达打印到控制台的行。这意味着finally
在这种情况下,我将无法在块内抛出异常时释放块中的资源try
。
所以,我相信有两件事:要么我遗漏了什么,要么try
+finally
组合在 C# 中没有用例。第二个语句是有道理的,因为我将获得与上面的代码和下面的代码产生的相同的功能:
using System;
public sealed class Program
{
public static void Main()
{
int zero = 0;
int i = 1/zero;
Console.WriteLine("divide by zero"); //the …
Run Code Online (Sandbox Code Playgroud) c# ×5
ide ×3
asp.net-core ×2
.net ×1
.net-core ×1
arguments ×1
automapper ×1
constraints ×1
directory ×1
exception ×1
finally ×1
generics ×1
git ×1
git-stage ×1
hint ×1
intellisense ×1
node.js ×1
omnisharp ×1
parameters ×1
routes ×1
shortcut ×1
try-catch ×1
try-finally ×1
types ×1