Usage of wrong compiler during SQL Server Database Project building - c#

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

Related

Microsoft.Typescript was not imported by Microsoft.NET.Sdk.Web.ProjectSystem

I am using VS Community Studio 2019 to build a new web page with ASP.NET. Upon creating new RESTful API templates, I receive this kind of error:
Project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\v16.0\TypeScript\Microsoft.TypeScript.targets" was not imported by "C:\Program Files\dotnet\sdk\3.1.200\Sdks\Microsoft.NET.Sdk.Web.ProjectSystem\targets\Microsoft.NET.Sdk.Web.ProjectSystem.targets" at (14,3), due to the file being invalid
It is also an issue for Microsoft.Typescript.Default.props and Microsoft.TypeScript.DotNetCore.targets, leading to an error (I guess) :Root element is missing.
Is there any solution for it?
For the same error in my case this worked :
1 - Go to NuGet packages manager
2 - Install this package : Microsoft.TypesCript.MSBuild
Regards
After reinstalling the TypeScript SDK, the error became an warning: "This is most likely a build authoring error. This subsequent import will be ignored."

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).

Error in Msbuild.exe for static enum class

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.

Switched targeted .NET versions and now project won't build

I'm running VS 2010 and I have a project which was originally set to build to .NET 4.0. This rev of .NET is too high for many of the windows platforms this app is expected to run and so I switched it from .NET 4.0 to .NET 2.0. Now, the project doesn't build.
At first I was getting null reference exceptions with the project resources. I found this link on MSDN forums which proved helpful in fixing that issue. Essentially, the answer (among the many) that worked was to change all instances of:
Version=4.0.0.0
to
Version=2.0.0.0
... in the *.resx files. I did this to all *.resx files I could find in the project directory. Walla, no more null reference exceptions during the build. However, now the project simply fails to build and the build window offers nothing in way of help to resolve. This is literally what's there:
2>CoreCompile:
2> C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:x86 /errorreport:prompt /warn:4 /define:TRACE /reference:C:\Users\afalanga\Dev\Tools\Program\FrontEnd\Resources\WrapNativeLibrary.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Management.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /debug:pdbonly /filealign:512 /optimize+ /out:obj\x86\Release\FrontEnd.exe /resource:obj\x86\Release\FrontEnd.Panel.resources /resource:obj\x86\Release\FrontEnd.PrivilegesForm.resources /resource:obj\x86\Release\FrontEnd.Main.resources /resource:obj\x86\Release\FrontEnd.Properties.Resources.resources /resource:obj\x86\Release\FrontEnd.SoftwareLicense.resources /resource:Resources\WrapNativeLibrary.dll,WindowsUpdateTool.Resources.WrapNativeLibrary.dll /resource:Resources\INativeLibrary.dll,FrontEnd.Resources.INativeLibrary.dll /target:exe /win32icon:Resources\FrontEnd.ico /win32manifest:Resources\app.manifest Environment.cs Check.cs Exceptions.cs Updater.cs LibAccess.cs PrivilegesForm.cs Form1.Designer.cs OSInfo.cs Constants.cs PersonalizationManager.cs Silent.cs drivePanel.cs drivePanel.Designer.cs Main.cs Main.Designer.cs Program.cs Properties\AssemblyInfo.cs SoftwareLicense.cs SoftwareLicense.designer.cs VerticalProgressBar.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs
2>
2>Build FAILED.
Is it due to the fact that the C# compiler being referenced is the 4.0 version? At this point, I'm completely at a loss for what to check. I'm considering a fresh checkout of the branch for this code from TFS and trying there but haven't gone that route yet. I would appreciate any insight as everything I can see from the project properties says it should be targeting .NET 2.0 and it "should" build.
Thanks,
Andy
When you're downgrading your build target, you might be better off to start with a new project, change the build target then import your code into it. This way all your core dependencies start out right, and you'll only have to worry about the code being able to work.

Categories