How to hide C# warning using project(.csproj) file - c#

One of the C# project uses multiple C++ DLLs. I want to hide below warning in the same project.
ALINK : warning AL1073: Referenced assembly 'mscorlib.dll' targets a different processor
I know it can be use C# code to do this using code file. But in my case I want to use the project file to do this.
In C++ project file, It can be done by
<Link>
<AdditionalOptions> /ignore:xxxx %(AdditionalOptions)</AdditionalOptions>
</Link>
Is there anyway to do this using C# project file?

In the .csproj file
Add the tag <NoWarn>1073</NoWarn> to the desired build configuration in a <PropertyGroup> tag. Suppress multiple warnings by inserting a ;.
In Visual Studio
Right click the project -> property -> build tab
You can explicitly specify the warning you would like to hide or lower the warning level to do that.
Please see the two posts below for reference:
https://msdn.microsoft.com/en-us/library/jj715718.aspx
https://msdn.microsoft.com/en-us/library/13b90fz7(v=vs.120).aspx

Related

Suppress Blazor css ::deep warning

In a css file of an asp.net Blazor app when I use ::deep VS emits a warning "Validation (CSS 4.0): "::deep" is not a valid pseudo-element." That might be true for regular CSS, but not in the context of a Blazor app.
Is there a way to suppress it? Right-click -> Suppress -> In File / In Source do nothing.
You can add deep to the vendor specific extensions.
I've added it to the Microsoft extension and it works.
Open with an editor (in Administrator mode) the file:
C:\Program Files (x86)\Microsoft Visual Studio\2019\<your version>\Common7\IDE\Extensions\Microsoft\Web Tools\Languages\Schemas\CSS\1033\css-vendor-ms.xml
Go to line ~69 and add the following code:
<CssPseudo name="::deep"
_locID="ms-browse-pseudo-element"
_locAttrData="description"
version="3.0"
browsers="IE11"
description="Blazor child component support."
standard-reference="https://learn.microsoft.com/en-us/aspnet/core/blazor/components/css-isolation?view=aspnetcore-5.0"/>
Restart Visual Studio.
Now I can see the source code as:
For Resharper users, editing the css-vendor-ms.xml is needed but does not completely solve the issue. Resharper will continue to highlight ::deep elements as errors in your solution. This is currently a known bug, which will hopefully be resolved in a future build.
As a work around, go to Resharper Options --> Code Inspection --> Inspection Severity --> CSS --> Potential Code Quality Issues --> Unknown CSS symbol and drop the severity to Warning (or lower).
This has now been fixed as of the latest preview version of Visual Studio 2022:
https://developercommunity.visualstudio.com/t/Support-::deep-in-razorcss-CSS-isolati/1623976
I just downloaded 17.3 and my project is now down to zero warnings again! Look forward to it being released properly.

Is it possible to add custom properties to a .csproj file use by Visual Studio

I'm developing a creation tool that will be compiling media objects as well as C# code into a certain format
This tool will be compiling C# code directed by a standard Visual Studio csproj file. Ideally i would like to store non C# project related information alongside the information about that code structure and compile instructions, such as media locations and compile information. This extra information/content will not be built with MSBuild.
My optimum way to do this would be to store all of the compile and structure information into one project file for example a csproj file. My initial investigation into doing this lead to Visual studio complaining about unrecognized tags when loading the project.
My main question is: Is there a way for me to store extra non-MSBuild related data inside a csproj file without Visual Studio or MSBuild complaining about unrecognized XML tags.
Looks like you can extend the information inside the csproj files with custom tags/properties.
See this: Adding custom information to CSPROJ files

Disable warnings for automatic generated code/folder/namespace

I like to have clean, "0 warnings" - projects in C#. This includes my project having XML comments for every public property and class.
Now I use entity framework with migrations (code first). The migrations are created by using "Add-Migration" which cause automatic code to be generated in the Migrations folder (standard behavior). I might want/need to modify these classes a bit but do not want to add Comments for the public classes created there.
I know I can disable the warnings using #pragma disable but again do not want to have to do this for every Migration-class.
So: Is there a possibility to use #pragma disable (or something similar) on a complete folder or namespace?
I do NOT want to use something like GhostDoc as a workaround.
Add a new .editorconfig file to that specific folder with this content:
[*.cs]
generated_code = true
dotnet_analyzer_diagnostic.severity = none
To suppress warnings for generated code in a project
Right-click the project in Solution Explorer, and then click
Properties.
Click Code Analysis.
Select the Suppress results from generated code check box.
Reference: How to: Suppress Code Analysis Warnings for Generated Code

WP8 define multiple preprocessor values

I know that we can declare Preprocessor values in the properties settings of any app.
I can declare two or three macros in the Conditional compilation symbols, but what if I want to define 25 values here? Is there any other way, like a .cs file where I can link all my definitions here.
You can manually edit the .csproj file using Visual Studio's text editor.
Right click on your project in Solution Explorer.
Select Unload Project
Right click on your (unloaded) project in Solution Explorer.
Select Edit MyProject.csproj
Find the DefineConstants elements and edit your defined symbols there directly. The settings for Debug and Release configurations are in separate PropertyGroup elements.
Right click on your (unloaded) project in Solution Explorer.
Select Reload Project
No, you can't define them somewhere and use in the other files. MSDN page about define says:
The scope of a symbol that was created by using #define is the file in
which the symbol was defined.

Add compile parameter to csc command using Visual Studio IDE

The solution consists of two projects: main.csproj and helper.csproj.
What Id'like to do is using dll which helper project will be complied into, as an embedded resource for main.dll.
For that purposes it's seems resonable to add custom compile attribute for project main: /resource: <path to dll>.
The problem is I can't find how to add this compile parameter through the Project Property.
PS Maybe someone can suggest other solution to avoid making changes in compile process.
You should be able to add the helper assembly as a resource in the main.csproj. That will make MsBuild generate the correct parameters for csc.
(MsBuild is the build engine used by .NET in general up to and including 4.x and is also used by VisualStudio.)
What you can do to set this up is:
Right click the Main project in the Visual Studio solution explorer and select Add existing item. Add the assembly to be embedded as a linked item from the bin folder of the helper project. (click the little arrow on the Add button in the selection dialog to access the option to add as a link).
In the properties for the item in the Main project, set Action to Embedded resource.
Tricky bit would be to include the correct build so that you include the debug build or the release build depending on what configuration you are building.
If you need that, you can either:
edit main.csproj file to include the ${Configuration} variable in the path for the helper dll.
Add a pre-build step to the main.csproj file to copy in the assembly to a fixed place and include the file from there (the include as link bit is no longer needed then)
To make sure you always build the helper assembly when you build the main assembly I would recommend you add a project reference to the main project.

Categories

Resources