我已经下载了一个带有项目格式示例的框架.csproj。如何在 MonoDevelop 中打开它们?
我有兴趣使用该框架中的一些类。它的文件夹结构如下: Accord.Statistics.Models 和一个主文件夹 Accord 以及一个子文件夹 stats 和一个子文件夹 Models 以及一个文件 ModelFoo.cs
我想使用该文件(以
namespace Accord.Statistics.Models
Run Code Online (Sandbox Code Playgroud)
)在 Ubuntu 下的 MonoDevelop 解决方案中。
如果我在新解决方案中复制文件夹或单个文件,则会收到错误
您是否缺少 using 指令或程序集引用?
我能怎么做?
我们的项目使用 StyleCop 来执行编码标准。我们的目标是将所有 StyleCop 警告视为错误。然而,我们只想在发布版本上强制执行此操作。由于代码不断变化,直到开发人员准备好执行签入为止,因此我们不希望 StyleCop 错误抱怨甚至可能无法进入源代码管理的代码段。
目前我们必须在 csproj 文件中执行此操作:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
目前我必须设置StyleCopTreatErrorsAsWarnings每个配置组合。是否有一个通用的发布和调试标记,我可以使用它在所有调试版本和所有发布版本上StyleCopTreatErrorsAsWarnings设置,而不是单独设置?truefalse
我希望能够在另一个项目中使用我的 Nuget 包时对其进行调试。过去,我会在运行 nuget.exe 时添加“-sym”,但我目前正在使用新的 csproj(因此打包是构建的一部分)并且希望能够执行相同的操作。既然 nuget.exe 是构建过程的一部分,任何人都知道我如何有效地做到这一点。
在“旧”世界中,我会定义一个AssemblyProductAttribute并且AssemblyTrademarkAttribute它会在 Windows 资源管理器的文件属性中显示为“产品名称”和“合法商标”。
在 Visual Studio 2017 中用于 netstandard 项目的新简化 msbuild 系统中,首选方法是直接在 csproj 中定义所有这些程序集级别的属性,并让 msbuild 生成实际属性。
但是似乎没有办法在 csproj 中定义“产品名称”和“合法商标”。或者有吗?这个 msbuild 目标似乎暗示它应该至少适用于AssemblyProductAttribute.
我怎样才能添加这两个东西?
Udapte:
好的,所以对于AssemblyProductAttribute 中的可以直接写入<Product>Foo</Product>csproj 文件。但是AssemblyTrademarkAttribute呢?
在我的.net core申请,我想有我使用的标签给定文件划归就像是一个.NET Framework应用程序的部分文件DependentUpon中csproj。
如图所示,我希望所有Program.*.cs文件都在Program.cs.
但是,在.csproj文件中,我没有看到列出的文件:
有没有办法在.net core应用程序中做到这一点?
我最近升级到 Unity 2019.3.0f6。当我打开我的一个 c# 文件时,我注意到 UnityEngine.UI 未被识别为有效的命名空间。这导致每当我引用此命名空间时都会出现红色波浪线。IntelliSense 也停止工作。这个问题只出现在 VSCode 中,我的项目在 Unity 中仍然运行得很好。
我检查了 Omnisharp 日志并发现了一些错误,这些错误告诉我 Omnisharp 无法找到 UI .csproj 文件和其他几个文件。
[warn]: OmniSharp.MSBuild.ProjectLoader
The referenced project 'UnityEngine.UI.csproj' does not exist.
Run Code Online (Sandbox Code Playgroud)
什么会导致这种情况?
我已经尝试过的事情:
.NET Core .csproj 文件中的文件路径位置在哪里?我编辑项目并打开它,但仍然没有一个 cs 类文件路径。
这是项目示例之一。该项目在解决方案资源管理器中预先树中有超过 1000 个 cs 文件。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<!--<TargetFramework>net461</TargetFramework>-->
<RootNamespace>Microsoft.Web.Api.R1.BusinessLogic</RootNamespace>
<AssemblyName>Microsoft.Web.Api.R1.BusinessLogic</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Folder Include="GraphQL\Microsoft\Microsoft\R1\" />
<Folder Include="MicrosoftHandlers\R1" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Containers" Version="0.25.0" />
<PackageReference Include="Microsoft.AccessTokenValidation" Version="2.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.Web.Api.R1\Microsoft.Web.Api.R1.csproj" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud) 我有许多正在生成的 C# 文件。我希望它们自动嵌套在 Visual Studio 解决方案资源管理器中匹配的 C# 文件下。例如,Foo.Generated.cs 和 Bar.Generated.cs 将分别嵌套在 Foo.cs 和 Bar.cs 下。
如果可能,我希望能够在我的 Directory.Build.props 文件中管理它,因此我的解决方案中的所有类库都将具有相同的行为。
版本
失败的尝试 A:
<Compile Update="**\*Generated.cs">
<DependentUpon>$([System.String]::Copy(%(Filename)).Replace('.Generated', '.cs'))</DependentUpon>
</Compile>
Run Code Online (Sandbox Code Playgroud)
失败的尝试 B:
<Compile Update="**\*Generated.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
Run Code Online (Sandbox Code Playgroud)
失败的尝试 C:
<Compile Update="**\*Generated.cs">
<DependentUpon>%(Filename).cs</DependentUpon>
</Compile>
Run Code Online (Sandbox Code Playgroud)
上述方法也已尝试过:
<ItemGroup>
<ProjectCapability Include="DynamicDependentFile" />
<ProjectCapability Include="DynamicFileNesting" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud) /p:Platform=x64这个问题是关于在 MSBuild 命令行上使用与<Platform>x64</Platform>在 csproj 文件中使用之间的区别。
我制作了两个简单的 c# NET 5 解决方案/项目,其中包含一个可执行文件 (HsConsole) 和一个类库 (HsLogger),以调查何时发生 MSB3270 架构不匹配。这是错误消息示例。
warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "HsLogger", "AMD64".
Run Code Online (Sandbox Code Playgroud)
** 请注意,错误消息涉及 MSIL (hsconsole) 和 AMD64 (hslogger),即使命令行和项目文件都指定 x64 而不是 AMD64。
HsLogger 记录器使用构建后事件将类库复制到存储用于在项目之间共享的库的文件夹。HsConsole 项目引用该文件夹中的类库 HsLogger。
问题是,每当我/p:"Platform=x64"在 MSbuild 命令行上使用时,我都会收到 MSB3270 错误消息(编译 HsConsole 时),但当我在命令行上不使用任何参数时,不会收到 MSB3270 错误消息。<Platform>x64</Platform>在这两种情况下,已在 HsLogger 项目文件中声明。
这是两个项目文件:
HsLogger
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Platform>x64</Platform>
<TargetFramework>net5.0-windows7.0</TargetFramework>
</PropertyGroup> …Run Code Online (Sandbox Code Playgroud) 我有一个.NET Framework 4.5.2 WebAPI2项目。在Visual Studio中构建项目时,我希望在每次构建之前都运行我编写的Powershell脚本。如果powershell脚本以任何非零代码退出,则我希望构建失败,并且来自powershell脚本的错误消息在Visual Studio输出中可见。
到目前为止,这是我修改csproj文件的方式:
<Project ToolsVersion="12.0" DefaultTargets="MyCustomTarget;Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
<Target Name="MyCustomTarget">
<PropertyGroup>
<PowerShellExe Condition=" '$(PowerShellExe)'=='' ">
%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
</PowerShellExe>
<ScriptLocation Condition=" '$(ScriptLocation)'=='' ">
C:\Code\MyScript.ps1
</ScriptLocation>
</PropertyGroup>
<Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted -command "& { $(ScriptLocation) } "" />
</Target>
Run Code Online (Sandbox Code Playgroud)
为了简单起见,我的脚本如下:
if(((get-date -Format "mm") % 2) -eq 0){ exit 0 } else { write-error "The minute is not equally divisible by 2.";exit 1 }
Run Code Online (Sandbox Code Playgroud)
但是,当我去构建项目时,我现在看到我的Powershell脚本在记事本中打开,并且构建停止,直到我关闭记事本。关闭后,我遇到了错误,但找不到任何解决错误的方法。任何帮助将不胜感激。
The command "
%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
-NonInteractive -executionpolicy Unrestricted -command "& {
C:\Code\MyScript.ps1
} "" exited …Run Code Online (Sandbox Code Playgroud) csproj ×10
c# ×6
msbuild ×4
.net-core ×3
asp.net ×1
debugging ×1
monodevelop ×1
msbuild-task ×1
nuget ×1
omnisharp ×1
powershell ×1
stylecop ×1
ubuntu ×1