Error in Msbuild.exe for static enum class - c#

I have enums added in the static partial class (Helper.cs). When i reference this enum in other files, automatically using block is added like - "using static Common.Util.Helper"
So If i do msbuild from folder - "Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" its not working and giving an error like below -
error CS1041: Identifier expected; 'static' is a keyword
But in VS 2015 it builds fine. I am using VS 2015 and Framework version 4.5. So do i need to any settings in msbuild or any solution for this ?
Thanks in advance !!

Use
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
instead.

Related

Getting an error building VS project using Microsoft.Build after update

I have a C# project that builds another project using Microsoft.Build library. It worked perfect until I upgraded VS to version 16.11.5. Now, I am getting the error in the logger file below when executing project.Build():
ERROR C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4693,7): The "WroteAtLeastOneFile" parameter is not supported by the "Copy" task. Verify the parameter exists on the task, and it is a gettable public instance property.
I tried manually building from VS and it works but not when building via code.
Open the Microsoft.Common.CurrentVersion.targets file and delete the folllowing element and save the file:
<Output TaskParameter =” WroteAtLeastOneFile “PropertyName =” WroteAtLeastOneFile “/>

Building cmake generated UWP windows desktop project results in error MC6000 (missing WindowsBase, ...)

I created a simple Windows UWP solution with windows visual studio 2019.
I did not make any changes to it but closed visual studio.
Then I wrote a simple cmake file for it.
However, it fails in "cmake --build" like this:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(268,9):
error MC6000: Project file must include the .NET Framework assembly
'WindowsBase, PresentationCore, PresentationFramework' in the reference list.
[App1\out\App1.csproj]
When I add the requested .NET files with VS_DOTNET_REFERENCES property, there is a different error:
App1\MainPage.xaml(9,5): error MC3074: The tag 'ThemeResource' does not exist
in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.
Line 9 Position 5. [App1\out\App1.csproj]
I also tried adding all and combinations of these calls to CMakeLists.txt but they did not have any effect:
set_property (SOURCE "App.xaml" PROPERTY VS_XAML_TYPE "ApplicationDefinition")
target_compile_options (App1 PRIVATE "/langversion:default")
set_property (TARGET App1 PROPERTY DOTNET_TARGET_FRAMEWORK_VERSION "v4.7.2")
set_property (TARGET App1 PROPERTY WIN32_EXECUTABLE TRUE)
I cannot overcome these problems.
I generate and compile the solution like this:
cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -S . -B out
cmake --build out
Cmake version is 3.14.19050301-MSVC_2.
The source files are here, including the original by visual studio created solution files and my written CMakeLIsts.txt file.
Expected result would be a cmake compiling solution which looks as much as possible like the native solution.
Probably there is just a simple error but I cannot find it.

"Telemetry" task was not found

I am getting the following error when I create new .net core project on VS2017:
Error MSB4036 The "Telemetry" task was not found. Check the following:
1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the
Microsoft.Build.Framework.ITask interface. 3.) The task is correctly
declared with in the project file, or in the *.tasks files
located in the "C:\Program Files (x86)\MSBuild\12.0\bin"
directory. ConsoleApp8 C:\Program
Files\dotnet\sdk\2.1.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets 106
How can I solve this issue?
This error looks like you were trying to use the MSBuild version of an older Visual Studio version.
Be sure to only use dotnet commands or the MSBuild version distributed with Visual Studio or other self-contained MSBuild 15 distributions (e.g. by JetBrains).

Visual Studio 2017 publish ASP.NET Core app with C# 7.2

I have a Asp.Net MVC Core website that's using public static async Task Main(). For that to work I've set the language version to C# 7.2 (in the properties -> build -> advanced dialog, double checked in the csproj) for both Debug and Release build configurations.
App builds and starts fine in both Debug and Release mode.
Now, I'm trying to publish it to an Azure Website directly from Visual Studio 2017 15.5.2 (with WebDeploy) and I get this:
Program.cs(17,29): Error CS8107: Feature 'async main' is not available
in C# 7.0. Please use language version 7.1 or greater. CSC(0,0): Error
CS5001: Program does not contain a static 'Main' method suitable for
an entry point
In the output window I see it's running C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe with some flags, probably one of them is wrong?
Anyone know if this is a known issue or I'm doing something wrong?
This appears to be a bug in Visual Studio.
Adding this line to main property group in the .csproj file resolved the issue for me:
<LangVersion>latest</LangVersion>
The issue was also reported here in the ASP.NET Home repository.
Not an answer, per se, but for what it's worth async Main is just syntactic sugar. Behind the scenes Roslyn just adds the standard void Main wrapper construction:
static void Main(object[] args)
{
MainAsync(args).GetAwaiter().GetResult();
}
static async Task MainAsync(object[] args)
{
// your code
}
It's probably not worth your time trying to get the server on the same page C# version-wise, just to save literally three lines of code.

Usage of wrong compiler during SQL Server Database Project building

I have an issue with compilation of SSDT SQL Server Database Project by using Visual Studio 2015. I want to use C# 6 features inside my database project, but it seems like it is unsupported.
For example, I have added the next class in my db project:
namespace Database1
{
class ClassFile1
{
public string Str { get; } = string.Empty;
}
}
I have tried to compile this, but I got the error:
CS1519: Invalid token '=' in class, struct, or interface member declaration
I have found out that the reason of this error is wrong version of compiler that used by VS 2015. The next compilation line is generated by VS:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\mscorlib.dll" /debug+ /debug:full /optimize- /out:obj\Debug\Database2.dll /subsystemversion:6.00 /target:library /warnaserror- /utf8output ClassFile1.cs
As you can see, C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe is used and it is wrong.
I have tried compile db project from Developer Command Prompt for VS 2015 and this was done successfully, because inside this prompt csc.exe is Roslyn compiler (C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe) that support C# 6 features. You can check question How to run Roslyn instead csc.exe from command line?
I tried to compile the project by using MSBuild 14.0 and it was successfully done too.
The question is: how can I change/override version of compiler that my VS used for compilation of SSDT DB project from old C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe to new Roslyn compiler (C:\Program Files (x86)\MSBuild\14.0\Bin\csc.exe)?
I was trying to do this as well and faced the same problem. My workaround is to create a separate regular class library project. I moved the C# code from my Database project into the new library (which will be compiled using C# 6/Roslyn by VS 2015). And then reference this class library from my Database project.
Just remember to set the properties of the reference to the class library: Model Aware=true and Generate Sql Script=true. I haven't tested this thoroughly, but I was able to deploy it from my Database project by using the publish command, and call the function inside the class library.
Good news!
Visual Studio 2017 will use the current C# compiler for SSDT Database Projects, so all the features of
C# 6 will finally work in SQL Server assemblies.
The path of the used compiler is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\csc.exe
Because all of the C# 6 features are just pure compiler features you can now even use them if you are only targeting .NET 3.5 and SQL Server 2008.
In Visual Studio 2017 RC, I was also able to use some C# 7 features like expression bodied constructors, the new out variables, ref returns, the enhanced switch/is pattern matching and the improved binary/hex literals. But I was unable to use local functions or anything related to tuples like the new tuple return types, tuple literals or the new deconstruction declaration.
Maybe this behavior will change in the final release of Visual Studio 2017.
You will need to target the version of clr that is used by the version of SQL that you will be deploying to:
SQL 2005-2008 R2 = CLR 2
SQL 2012 = CLR 4
You can't just run any version of the clr that is on the machine I am afraid.
ed

Categories