Building solution in MS Build throws (Non-Displayable Char?) Error - c#

Building solution in MS Build fails with error(given the sample error below). But when i try to build the same solution in VS, the build succeeds. Once built in VS, if i try in MSBuild, then it works.
I came across This question where i found that non-displyable character may be the issue. So i commented '=>' characters and try building it again, it succeeded.
Error Thrown:
App\AllActions.cs(27,43): error CS1002: ; expected[D:\DEM1\AAA\framework\Core\Core.csproj]
App\AllActions.cs(27,50): error CS1520: Method must have a return type [D:\DEM1\AAA\framework\Core\Core.csproj]
My Code is,
public Alert Alert => new Alert();
public Button Button => new Button();
public Checkbox Checkbox => new Checkbox();
public Dropdown Dropdown => new Dropdown();
public Frame Frame => new Frame();
public Label Lable => new Label();
public Link Link => new Link();`
MSBuild version = C:\Program Files (x86)\MSBuild\12.0\Bin
Visual Studio 2017
c# Version = 7.0
Any help on how to sort this out?

The problem is likely that you are using a version of msbuild (MSBuild 12.0) that doesn't support expression bodied properties added in C# 7.0.
The msbuild version you are using is seemingly from 2015 which AFAIK doesn't support C# 7.0
Try a later version of msbuild

Related

GetTargetFrameworkIdentifier Static method invocation should be of the form: $([FullTypeName]::Method())

I am trying to get some net core 2.1 projects to build on a new build server that we have. We have installed Visual studio tools for 2017 and 2019.
I am getting this error when it tried to build it via our TFS build process. We use cake scripts to build the code.
C:\Program Files\dotnet\sdk\6.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(54,5): error MSB4186: Invalid static method invocation syntax: "[MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')". [MSBuild]::GetTargetFrameworkIdentifier Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)). [D:\Agents\EROS-006\_work\2\s\src\Cases.CommandHandlers\Cases.CommandHandlers.csproj]
Is it something to do with the csproj contents? We have this declared at the top as this bit of the message stands out
GetTargetFrameworkIdentifier Static method invocation should be of the form: $([FullTypeName]::Method())
The csproj version details:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.4</RuntimeFrameworkVersion>
<TargetLatestAspNetCoreRuntimePatch>True</TargetLatestAspNetCoreRuntimePatch>
</PropertyGroup>
...
I have searched for an answer but seem to point to mono related things, which we don't use at all, its a windows machine with the visual studio tools installed as mentioned above.
The cake build part looks like this
Task("Build")
.IsDependentOn("Version")
.Does(() =>
{
var settings = new DotNetCoreRestoreSettings()
{
Sources = packageSources
};
DotNetCoreRestore(settings);
if(useLatestMsBuild){
MSBuild(solution, new MSBuildSettings {
Configuration = configuration,
MaxCpuCount = maxcpucount,
ArgumentCustomization = args => args
.Append("/p:Version=" + versionInfo.InformationalVersion.Replace("/", "-"))
.Append("/p:AssemblyVersion=" + versionInfo.AssemblySemVer)
.Append("/p:FileVersion=" + versionInfo.AssemblySemVer)
});
}else{
MSBuild(solution, new MSBuildSettings {
Configuration = configuration,
MaxCpuCount = maxcpucount,
ToolVersion = MSBuildToolVersion.VS2017,
Restore = true,
ArgumentCustomization = args => args
.Append("/p:Version=" + versionInfo.InformationalVersion.Replace("/", "-"))
.Append("/p:AssemblyVersion=" + versionInfo.AssemblySemVer)
.Append("/p:FileVersion=" + versionInfo.AssemblySemVer)
});
}
});
Looking at further build steps in cake and powershell there was mention of it compiling with mono instead of the default. Updating cake to version 2.0 and rewiting it from the ground up seems to resolve the issue.
Installing Visual Studio Build Tools 2022 and latest nuget.exe added to the environmental variable PATH seemed to help. Ideally installing everything that the build server has on it and running the same scripts locally helped a lot.

Visual Studio 2017: Incompatible VCProjectEngine and EnvDTE

I am currently working on a legacy project that supports multiple VS versions (VS 2008 to VS 2015) and now supporting VS2017, for C++ Applications.
The project itself is in C# (in VS 2015).
In it, I am required to convert an EnvDTE.project into a VCProjectEngine.VCProject.
This conversion is working for other versions, but for VS2017 NULL is returned.
The following is a minimized working code for VS 2015:
//Here, EnvDTE and VCProjectEngine provided for VS2015 are used.
using EnvDTE;
using Microsoft.VisualStudio.VCProjectEngine;
..
..
//Path for a small VS2015 solution file.
String slnPath = #"<**>\Project_2015\Project_2015.sln";
Type EnvDteType = Type.GetTypeFromProgID("VisualStudio.DTE.14.0");
object obj = System.Activator.CreateInstance(EnvDteType, true);
EnvDTE.DTE DteObject = (EnvDTE.DTE)obj;
EnvDTE.Solution SolutionObject = (EnvDTE.Solution)DteObject.Solution;
SolutionObject.Open(slnPath);
Projects ProjectObjects = SolutionObject.Projects;
foreach (Project project in ProjectObjects)
{
//vcpro generated successfully.
VCProject vcpro = project.Object as VCProject;
}
However, the same code for VS2017 gets NULL in vcpro.
//Here, EnvDTE and VCProjectEngine provided for VS2017 are used
using EnvDTE;
using Microsoft.VisualStudio.VCProjectEngine;
..
..
//Path for a small VS2017 solution file.
String slnPath = #"<**>\Project_2017\Project_2017.sln";
Type EnvDteType = Type.GetTypeFromProgID("VisualStudio.DTE.15.0");
object obj = System.Activator.CreateInstance(EnvDteType, true);
EnvDTE.DTE DteObject = (EnvDTE.DTE)obj;
EnvDTE.Solution SolutionObject = (EnvDTE.Solution)DteObject.Solution;
SolutionObject.Open(slnPath);
Projects ProjectObjects = SolutionObject.Projects;
foreach (Project project in ProjectObjects)
{
//vcpro is NULL.
VCProject vcpro = project.Object as VCProject;
}
Am I missing something here, or is it a genuine problem of VS2017?
In any case, How can we resolve this or any workaround for this?
Any help is most welcomed.
Thanks.

XAML MarkupCompilePass2 fails on a WPF project

When I try to build my WPF project I get the folowing error:Samotorcan.Client.WPF.Windows8\Views\MainWindow.xaml(1,17): error MC3074: The tag 'Window' does not exist in XML namespace 'clr-namespace:Samotorcan.Client.WPF.Windows8.Controls'. Line 1 Position 17.The problem only occurs when I try to use linq. If I have a line like this new List<object>().ToArray<object>(); somewhere in the MainWindow.xaml.csfile I get the above error and if I change it to new List<object>().ToArray(); the error disappears and the project builds successfully.I also checked the build log and it contains the same error at task MarkupCompilePass2.I am using .NET Framework 4.5 and Visual Studio 2012.EDITAfter playing with it a bit I managed to find out that it's not specificly related to linq an random changes like removing an unused file from a project or just removing parts of code like a simple string creating string s = new String(); fixes the error.At one point a simple change in a constructor from this
public LoggedEventArgs(string message)
{
Message = message;
}
to this
public LoggedEventArgs(string message)
{
// Message = message;
}
fixed the error.
Managed to find a workaround for the above error by moving all my controls from the project into a separate project just for controls.
Now there are no random errors on build because as it looks like it can always find the window and other controls that are now in a separate assembly.

How to fix Unity Container Warning: "ContainerElement.Configure(Unity.IUnityContainer) is obsolete"?

I have just installed Prism4 on my box and trying to get started working on a example of Unity (UnityContainer).
I am using SL4, Prism4, .Net Framework4, VS 2010 Ultimate.
I am getting a warning in the class Program.cs on line configSection.Containers.Default.Configure(container);
Microsoft.Practices.Unity.Configuration.ContainerElement.Configure(Microsoft.Practices.Unity.IUnityContainer)'
is obsolete: '"Use the UnityConfigurationSection.Configure(container,
name) method instead'
This is the code that I wrote:
var configurationSection = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
foreach (ContainerElement containerElement in configurationSection.Containers)
{
container =configurationSection.Configure(container, containerElement.Name);
}
I understand that the old method is deprecated and needs to be replaced, but how can this be done? The code I tried above seams to be not working correctly.
A previous method in the Unity library - Microsoft.Practices.Unity.Configuration.ContainerElement.Configure(Microsoft.Practices.Unity.IUnityContainer) has now been replaced with a new implementation UnityConfigurationSection.Configure(container, name).
It's telling you that the original method has been replaced by a new one the new version of the Unity library so just use the new method. If you want the legacy method you will need to use an old version of the Unity library.

How do I use the Mono.CSharp interpreter in Microsoft.NET

I was under the impression Mono's compiler was usable in Microsoft.NET
edit: updated blog posting here that I originally missed that explains some of it (is consistent with Justin's answers)
I created a simple class to try to use it
[TestFixture]
class Class1
{
[Test]
public void EXPR()
{
Evaluator.Run("using System;");
int sum = (int)Evaluator.Evaluate("1+2");
}
}
And a project in Visual Studio 2010 that references C:\Program Files (x86)\Mono-2.10.1\lib\mono\4.0\Mono.CSharp.dll.
However when I try to run this task I get the following exception, thrown at the Evaluator.Run call:
System.TypeInitializationException was unhandled by user code
Message=The type initializer for 'Mono.CSharp.Evaluator' threw an exception.
Source=Mono.CSharp
TypeName=Mono.CSharp.Evaluator
StackTrace:
at Mono.CSharp.Evaluator.Run(String statement)
at Experiments.Class1.EXPR() in W:\Experiments\Class1.cs:line 16
InnerException: System.TypeLoadException
Message=Method 'Mono.CSharp.Location.ToString()' is security transparent, but is a member of a security critical type.
Source=Mono.CSharp
TypeName=Mono.CSharp.Location.ToString()
StackTrace:
at Mono.CSharp.Evaluator..cctor()
InnerException:
A google confirms one other person asking this question but no answer. I tried to start reading the microsoft article on security transparent code but got confused quite quickly. Would someone be able to suggest a quick workaround to allow me to use this? And possibly summarise the security implications, if any, to me (in the context of my situation - in the future I hope to package it with a thick client application, to be used both internally and by end-users)
It has worked under .NET since April of last year.
Small point but I notice you are missing a semi-colon in your expression for sum.
int sum = (int)Evaluator.Evaluate("1+2;");
I only have Mono 2.11 (from git) at the moment and they have changed to using a multi-instance version of the compiler instead of the static version. So, my code looks a little different:
using System;
using Mono.CSharp;
namespace REPLtest
{
class MainClass
{
public static void Main (string[] args)
{
var r = new Report (new ConsoleReportPrinter ());
var cmd = new CommandLineParser (r);
var settings = cmd.ParseArguments (args);
if (settings == null || r.Errors > 0)
Environment.Exit (1);
var evaluator = new Evaluator (settings, r);
evaluator.Run("using System;");
int sum = (int) evaluator.Evaluate("1+2;");
Console.WriteLine ("The sum of 1 + 2 is {0}", sum);
}
}
}
EDIT: I guess I should confirm that I did in fact successfully execute this on .NET 4 (using Visual C# Express 2010 on Windows XP)
EDIT AGAIN: If you have Visual Studio, you can download the latest version of Mono.CSharp and compile it yourself. There is a .sln (solution file) included with the source so you can build it on Windows without Mono. The resulting assembly would run the code above. Miguel has a post explaining the new Mono.CSharp here.
FINAL EDIT: I uploaded the compiled Mono.CSharp.dll assembly that I actually used here. Include it as a reference to compile the code above.
It looks like this is a bug in Mono.
.NET 4 abandoned Code Access Security but kept the concept of Security Transparent Code. In a nutshell, low-level code that does stuff, like call unmanaged code, must be "security critical". Application level code is marked "transparent". "Transparent" code cannot call into "security critical" code.
It sounds like Mono.CSharp.Location.ToString() needs to be marked with the [SecuritySafeCritical] attribute if you want the Mono 2.10 code to work with .NET 4. Maybe even better would be marking all of Mono.CSharp as SecuritySafeCritical.
http://msdn.microsoft.com/en-us/library/system.security.securitycriticalattribute.aspx
PS. Sorry to have multiple answers for one question. After I realized that 2.11 would work, I became more curious about what the error with 2.10 meant. I cannot really combine this answer with the others.
I decided I should have kept the code more like the question but I did not want to overwrite my previous answer:
The code below works with version 2.11 of Mono.CSharp (available here including a solution file for building with Visual Studio/.NET). It was tested with .NET 4 on Windows XP. I do not have access to Mono 2.10 at the moment.
[TestFixture]
class Class1
{
private Evaluator evaluator;
public Class1()
{
var report = new Report(new ConsoleReportPrinter());
evaluator = new Evaluator(new CompilerSettings(), report);
}
[Test]
public void EXPR()
{
evaluator.Run("using System;");
int sum = (int)evaluator.Evaluate("1+2;");
}
}
EDIT: I uploaded the Mono.CSharp.dll assembly that I actually used here. Include it as a reference to compile the code above.

Categories