Il s'agit d'un code de test C# 6 fonctionnel. Il compile sur VS2015Erreur lors de la compilation de C# 6 avec Microsoft.Build (Visual Studio SDK)
namespace testcode
{
class Program
{
static void Main(string[] args)
{
string x = null ;
string y = x?.Substring(0, 2);
return;
}
}
}
Le cproj
a ToolsVersion 14.0
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Voilà comment je suis en train de le compiler avec MSBUILD via le SDK Visual Studio
//References Microsoft.Build and Microsoft.Build.Framework
namespace MSBuildTest
{
class Program
{
static void Main(string[] args)
{
var pc = new Microsoft.Build.Evaluation.ProjectCollection(Microsoft.Build.Evaluation.ToolsetDefinitionLocations.Registry);
pc.DefaultToolsVersion = "14.0";
pc.RegisterLogger(new Microsoft.Build.Logging.ConsoleLogger(Microsoft.Build.Framework.LoggerVerbosity.Detailed));
var pr = pc.LoadProject(@"C:\path\to\testcode.cproj");
pr.Build();
}
}
}
Ceci est le message d'erreur
Program.cs(8,26): error CS1525: Invalid expression term '.' Program.cs(8,27): error CS1003: Syntax error, ':' expected 0 Warning(s) 2 Error(s)
je suppose qu'il utilise le mauvais exécutable MSBUILD, mais je trouve aucun moyen de forcer le chemin bin MSBUILD.
-vous un re construire avec C# v5 je suppose. – DavidG
@DavidG mais comment résoudre ce problème? – xvan
Peut-être référence les bonnes bibliothèques 'Microsoft.Build. *'? Quel est le chemin complet pour eux? – DavidG