Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I ignore optional parameter error on MSBuild 3.5

I am using Visual Studio 2010.

I've donwloaded an updated class (i.e. UpdatedClass.cs) which has a method with optional parameter, such as:

public void DoThis(bool aValue = false) {...}

Using Visual Studio 2010, I am able to compile it. But I cannot do it with MSBuild:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe /t:Rebuild /clp:ErrorsOnly D:\folder\mySolution.sln
ln
Microsoft (R) Build Engine Version 3.5.30729.5420
[Microsoft .NET Framework, Version 2.0.50727.5448]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

UpdatedClass.cs(29,94): error CS0241: Default parameter specifiers are not permitted

Well, optional parameters are not permitted using this compiler. So can I add an extra argument in this MSBuild command, to ignore this kind of error?

Or do I have to compile the project using C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe ? Is this safe regarding asp.net projects?

like image 554
Junior Mayhé Avatar asked Oct 08 '22 07:10

Junior Mayhé


1 Answers

If you are using C# 4 syntax, you have to use a 4.0 compiler. And this means you need to run .Net 4.0 on the server where you intend to deploy this code. Alternatively - rewrite the code not to use default parameters, that's not hard - just add an overload like this:

public void DoThis() {DoThis(false);}
public void DoThis(bool aValue) {...}
like image 67
skolima Avatar answered Oct 12 '22 19:10

skolima