0

I'm working in an environment in which all projects are placed into a Global Solution irrelevant of the specific business areas of the projects. So the solution is a monstrosity. I'm accustomed to a more segregated approach based on separation of concerns; but that's irrelevant to the question.

One of the projects in this solution was written in VB.NET and there is a section of code which is using the #Disable and #Enable directives as described here

According to Microsoft the directives are valid and if I perform a specific build within Visual Studio against the project containing these directives; I get a successful build.

However, this organization requires a preliminary successful build using MSBuild from a command prompt to ensure that it will build on the build server. Which I cannot get because MSBuild reports:

error BC30248: 'If', 'ElseIf', 'Else', 'End If', 'Const', or 'Region' expected.

Here is the actual code block that is throwing the error:

Protected Overrides Function ConvertToString() As IOperand 
  #Disable Warning BC42322
    Return MyValue.ToString() 
  #Enable Warning BC42322
End Function

The best I can conclude is that there must be some MSBuild optional flag that needs to be set prior to performing the build to accomodate for this and prevent the error or these directives are deprecated. Not 100% certain which is the case though (if either) but I do need to get the code to build successfully under MSBuild.

If they were warnings, I could simply ignore them but hence it is not the case.

Also, I've already tried using different versions via the /p:VisualStudioVersion switch. The results are all the same.

Mark
  • 1,667
  • 2
  • 24
  • 51
  • Which version of Visual Studio/MSBuild are you using? Those directives are only be supported in VB.Net version 14. – Chris Dunaway Aug 14 '17 at 13:26
  • Instead of trying to find a way to make this code compile without errors via directives, why not address the underlying issue that you have a Function called `ConvertToString` that returns an `IOperand` that is created via an implicit conversion from a `String`. The original code was obviously compiled with `Option Strict Off`. I would only use this mode where it is absolutely necessary to support late-binding code and then only at the code file level (not the whole project). – TnTinMn Aug 14 '17 at 14:01
  • @ChrisDunaway - MSBuild version 4.0.30319.33440 is what I'm running. What version should I be using that would support VB.Net v.14? – Mark Aug 14 '17 at 14:15
  • @TnTinMn - I agree totally that the underlying issue should be addressed but I don't own the code; otherwise that would be my first choice for resolution. That said, if its true that the code presumably compiled with Option Strict Off; shouldn't there be a way to designate that condition using MSBuild? – Mark Aug 14 '17 at 14:20
  • How did you determine that version number. When I run `MSBuild /ver` from the command line under Visual Studio 2015, I get version `14.0.25420.1` – Chris Dunaway Aug 14 '17 at 15:21
  • Adding to previous comment on use of Option Strict being Off, I confirmed the option setting as being applied to the entire project. When I turned it on then there were many lines of code err'd due to reliance of the setting. So looks like it would require potential rework of more code than desirable. – Mark Aug 14 '17 at 15:24
  • @ChrisDunaway - Sorry, that was my mistake. I actually gave you the assembly version # acquired from the assemblies property window. The version reported from the command line is 4.7.2053.0. I have parallel versions of Visual Studio on this system so I'm going to mod the environment to specify version 14 explicitly and try the build again to see if it will alleviate the issue – Mark Aug 14 '17 at 15:39
  • Well unfortunately using the installed version for my VS2015 which is 14.0.25420.1 doesn't seem to resolve the error. If version 14 is supposed to support the directives in question; I don't know what the problem could be now – Mark Aug 14 '17 at 15:57

0 Answers0