85

This will hopefully be an easy one. I have an F# project (latest F# CTP) with two files (Program.fs, Stack.fs). In Stack.fs I have a simple namespace and type definition

Stack.fs

namespace Col

type Stack= 
 ...

Now I try to include the namespace in Program.fs by declaring

open Col

This doesn't work and gives me the error "The namespace or module Col is not defined." Yet it's defined within the same project. I've got to be missing something obvious

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • 3
    As a tip: if you need to change the order of the files in Visual Studio, install [F# PowerTools](https://visualstudiogallery.msdn.microsoft.com/136b942e-9f2c-4c0b-8bac-86d774189cff), and use `Alt+Arrow` in the solution explorer to move them around (or right-click). You can also move them to other folders, or create new folders etc. – Abel Dec 16 '15 at 22:11

5 Answers5

92

What order are the files in the .fsproj file? Stack.fs needs to come before Program.fs for Program.fs to be able to 'see' it.

See also the start of

http://lorgonblog.spaces.live.com/blog/cns!701679AD17B6D310!444.entry

and the end of

http://lorgonblog.spaces.live.com/blog/cns!701679AD17B6D310!347.entry

Roly
  • 2,126
  • 2
  • 20
  • 34
Brian
  • 117,631
  • 17
  • 236
  • 300
  • 1
    Perfect! extra characters added to satifsy comment restrictions. – JaredPar Oct 06 '08 at 00:23
  • 1
    This one caught me out too, I would have thought that the F# compiler could just have a quick check in all the other files and look for the missing modules... seems simple enough – Ed Ayers Jul 19 '11 at 09:26
  • "What order are the files in the project?" what does this mean? All the files are in the same folder. – runeks Mar 28 '19 at 08:26
  • The order in which the files are listed in the .fsproj file is what matters. Visual Studio Solution Explorer should list them in that same order and provide context menu commands to move them up or down. – Scott Hutchinson Jul 07 '19 at 17:51
46

I had the same problems, and you are right, the order of the files is taken in account by the compiler. Instead of the Remove and Add pattern, you can use the Move Up / Move Down items in the context menu associated to the .fs files. (Alt-Up and Alt-Down are the shortcut keys in most of the standard key-bindings)

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
  • I believe these key bindings are only available with F# PowerTools installed (but most F# users install them anyway). – Abel Oct 09 '16 at 21:22
17

All of the above are correct, but how to do this in VS2013 is another question. I had to edit my .fsproj file manually, and set the files in exact order within an ItemGroup node. In this case it would look like this:

<ItemGroup>
    <Compile Include="Stack.fs" />
    <Compile Include="Program.fs" />
    <None Include="App.config" />
</ItemGroup>
Benj Sanders
  • 481
  • 5
  • 15
  • Or you could've simply installed [F# PowerTools](https://visualstudiogallery.msdn.microsoft.com/136b942e-9f2c-4c0b-8bac-86d774189cff), which allows you to move a file up or down, move them to a directory, or out of it, and much more. Will save you a lot of time. – Abel Dec 16 '15 at 22:10
  • 2
    Just had this occur in VS2015 - moving files up or down wasn't fixing the issue - had to edit the .fsproj file manually. - Possible bug in F# PowerTools – jps Sep 15 '16 at 19:45
  • 1
    @jps, yes, I noticed some bugs with PowerTools too, esp. when moving directories up/down (they end up at the bottom in fsproj, but appear higher in VS). Moving within one directory usually goes right (for me). Luckily you can now edit the fsproj directly within VS2015. – Abel Oct 09 '16 at 21:20
1

I had the same issue and it was indeed the ordering of the files. However, the links above didn't describe how to fix it in Visual Studio 2008 F# 1.9.4.19.

If you open a module, make sure your source file comes after the dependency in the solution explorer. Just right click your source and select Remove. Then re-add it. This will make it appear at the bottom of the list. Hopefully you don't have circular dependencies.

Jen S.
  • 4,106
  • 4
  • 35
  • 44
0

I'm using Visual Studio for Mac - 8.1.4 and i've noticed that some .fs files are not marked as "Compile". You can see this by Viewing Build Output and see if all your files are there and in the correct order.

I've had to manually make sure certain files are marked with "Compile", and have had to move them up and down manually until it "takes".

Doug
  • 14,387
  • 17
  • 74
  • 104