Wiki

Ticket #371 (new defect)

Opened 10 years ago

Last modified 10 years ago

MSBuild Task: error if no assembly references in .cobraproj file

Reported by: thriwkin Owned by:
Priority: minor Milestone:
Component: Cobra Compiler Version: 0.9.6
Keywords: MSBuild Task, Cobra.MSBuild.dll Cc:

Description

On Windows, using "msbuild.exe" with a file "X.cobraproj" without any assembly references, for example

<Reference Include="System" /> 

causes this error message:

...Cobra.targets(149,3): error MSB6001: 
    Invalid command line switch for "cobra.bat". 
    Value cannot be null. [...X.cobraproj]
...Cobra.targets(149,3): error MSB6001: 
    Parameter name: collection [...X.cobraproj]

Steps to reproduce the failure:
call

msbuild X.cobraproj

where "X.cobraproj" is this file

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
  ToolsVersion="4.0" DefaultTargets="Build" >
  <PropertyGroup>
    <OutputPath></OutputPath>
    <AssemblyName>Hello</AssemblyName>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Hello.cobra" />
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)/Cobra/Cobra.targets" />
</Project>

and "Hello.cobra" is this file:

class Program
    def main is shared
        print "Hello!"

Note:
The above "X.cobraproj" works with "xbuild.exe".
With "msbuild.exe" it only works with an assembly reference, for example:

  ...
  <ItemGroup>
    <Compile Include="Hello.cobra" />
    <Reference Include="System" />
  </ItemGroup>
  ...

Change History

Changed 10 years ago by thriwkin

  • type changed from idea to defect
  • summary changed from Cobra.MSBuild.dll, on Windows, using msbuild: error if a .cobraproj file does not contain any <Reference Include=... /> to Cobra.MSBuild.dll: error on .cobraproj file without any assembly references.

The failure is caused by (a typo?) in file "CobraCompiler.cobra":

class CobraCompiler ...
    def generateCommandLineCommands as String ...
        ...
        refs = List<of ITaskItem>(.references)
        ...

A simple fix:

class CobraCompiler ...
    def generateCommandLineCommands as String ...
        ...
        if .references
            refs = List<of ITaskItem>(.references)
            ...

Note: This changeset does not fix the error:
http://cobra-language.com/trac/cobra/changeset/3061

Question:
To which "Component" belongs the Cobra MSBuild Task (Cobra.MSBuild.dll)?
The dropdown box "Component:" offers these options only:
- Cobra Compiler
- Cobra IDE: Miscellaneous
- Cobra Web Site: ...

Changed 10 years ago by nerdzero

Looks like a reasonable fix. Did you try it?

Just curious, how are you building these project files? By hand or by modifying the configuration parameters via the GUI screen in MonoDevelop?

Changed 10 years ago by thriwkin

  • summary changed from Cobra.MSBuild.dll: error on .cobraproj file without any assembly references. to MSBuild Task: error if no assembly references in .cobraproj file

Looks like a reasonable fix. Did you try it?

Yes, see below.

how are you building these project files?

With an editor (SciTE), on Windows,
because this X.cobraproj file is suitable for tests
- on Windows, .NET, msbuild.exe, and
- on Windows, Mono, xbuild.exe,
and it is as simple as possible (reduces the number of possible causes of a failure).

History
When I tried out the MD/XS addin (v0.5.1, end of last year)
I always encountered this failure, as described above.
When I looked into the source code of the MSBuild task (in CobraCompiler.cobra),
I found that it is caused by this statement

refs = List<of ITaskItem>(.references)

Then (end of last year) changeset:3061 appeared: instead of changing the source of the MSBuild Task, it changes 5 test/demo project files. To each file it adds an assembly reference (System.Core)
- which prevents the failure -- it causes that the Task parameter .references will not be nil,
- but which is not needed -- the Task has to remove it, because it cannot prevent that the Cobra compiler does implicitly add this reference.

So I wondered:
"Why do they not fix the bug by inserting an if .references, ... into the source of the Task?"

Later I got this idea: "Maybe it is an issue on .NET only, but not on Mono."
To test this, I made this simple X.cobraproj file.
With both, .NET and Mono installed on Windows, I can test:
- msbuild.exe X.cobraproj
- xbuild.bat X.cobraproj
(the xbuild.bat calls ...\mono.exe" %MONO_OPTIONS% ...\xbuild.exe" %*)

Results of the tests
1. If the .cobraproj file does not contain any assembly references
- on Mono with xbuild, the Task will be called with .references <> nil and .references.count == 0
- on .NET with msbuild, the Task will be called with .references == nil,
-- which causes that the statement refs = List<of ITaskItem>(.references) throws an Exception.

2. If the Task is modified as described above,
then the X.cobraproj runs
- with or without any assembly references, on both,
- on .NET with msbuild, and
- on Mono with xbuild,
where X.cobraproj is:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
  ToolsVersion="4.0" DefaultTargets="Rebuild" >
  <PropertyGroup>
    <OutputPath>bin</OutputPath>
    <AssemblyName>Hello</AssemblyName>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Hello.cobra" />
<!-- 
    <Reference Include="System" /> 
-->
 </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)/Cobra/Cobra.targets" />
</Project>

3. I also tested the modified Task with the MD/XS addin (v0.5.1, end of last year):
- on Windows, .NET, msbuild.exe: it worked with or without assembly references.

Changed 10 years ago by thriwkin

Correction:

Results of the tests (1.)

Correct is:
If the X.cobraproj file does not contain any assembly references
then

  • on Windows, .NET, msbuild: the Task will be called with .references == nil
    -- which causes that the statement refs = List<of ITaskItem>(.references) throws an Exception.
  • on Windows, Mono, xbuild, ToolsVersion="4.0": the Task will be called with .references <> nil and .references.length == 1 and .references[0].itemSpec: "...System.Core".
Note: See TracTickets for help on using tickets.