0

I'm keeping all my source files in a separate location to keep my trunk clean and organized. I simply point to this "SourceCode" location within my lua files but set my "location" to a completely separate "builds" directory. For the most part, this produces exactly the type of behavior I want and seems to be an elegant solution. Except...

When I run premake to generate project files, it's creating Link elements for each (Compile element) file that is included. As a result, an extraneous folder is created upon opening the solution file. That folder is never used again.

Ex excerpt of generated project file:

<ItemGroup>
    <Compile Include="..\..\SourceCode\FileUtilities\FileUtilities.cs">
      <Link>SourceCode\FileUtilities\FileUtilities.cs</Link>
    </Compile>
    <Compile Include="..\..\SourceCode\FileUtilities\FileWriter.cs">
      <Link>SourceCode\FileUtilities\FileWriter.cs</Link>
    </Compile>
</ItemGroup>

Upon opening the solution in VS2013, a "bin" and "obj" folder are created (as needed). But an extra "SourceCode" directory (and its children) is also created yet never used again. Is there a flag I can use to simply tell premake to NOT include Link blocks within the project files?

I am using premake5.

Here's how my directory structure is set up:

\trunk\builds
\trunk\SourceCode\<Contains separate folders for each projects source code>
\trunk\premake\solutions\<contains premake solution files>
\trunk\premake\projects\<contains premake project files>
\trunk\premake\configurations\<contains premake configuration files>

template solution file, 'solution-Template.lua':

solutionName = "Template"

solution(solutionName)

    location("../../builds/" .. solutionName)

    --Include a configuration file to define all your build settings
    include "../configurations/configurations-Template.lua"

    --List all the projects contained in your solution.
    --Note: The first project will be the default StartUp project
    include "../projects/project-Template.lua"
    include "../projects/project-AnotherProject.lua"

template project file, 'project-Template.lua':

projectName = "Template"

buildLocation = projectName
if solutionName ~= nil then
    buildLocation = solutionName .. "/" .. projectName
end

project(projectName)

    location("../../builds/" .. buildLocation)

    --kind is the output type of the project.
    --https://github.com/premake/premake-core/wiki/kind
    kind "SharedLib"
    --language is the programming language the project is written in
    --https://github.com/premake/premake-core/wiki/language
    language "C#"
    targetdir("../../builds/" .. buildLocation .. "/bin/%{cfg.buildcfg}")

    --List all the files used in the project using relative paths
    --The wild card "*" works (e.g. *.cs). "**" checks all child folders
    files
    {
        "../../SourceCode/Template/File1.cs",
        "../../SourceCode/Template/File2.cs",
        "../../SourceCode/Template/Etc.cs"
    }

    --List all the libraries/references that your project uses, including 
    --other projects
    links 
    {
        "System",
        "Template"
    }

template configuration file, 'configurations-Template.lua':

configurations { "Debug", "Release" }

--Define the platform configuration names. These can be named anything.
--Visual Studio will default to the first value upon opening the solution.
--Note: Be careful, 'Win32' is a predefined name and will be replaced with 'x86' even if
--you set the architecture to "x64".
platforms { "Win64", "Win32" }

--Set all the filters needed to produce the desired build/platform configuration results.
--https://github.com/premake/premake-core/wiki/Configurations_And_Platforms
filter "configurations:Debug"
    defines { "DEBUG" }
    flags { "Symbols" }

filter "configurations:Release"
    defines { "NDEBUG" }
    optimize "On"

filter { "platforms:Win32" }
    system "Windows"
    architecture "x86"

filter { "platforms:Win64" }
    system "Windows"
    architecture "x64"

I would then run the following command from command prompt in \trunk\premake:

premake5 --file=./solutions/solution-Template.lua vs2013

This results in a folder being created in my \trunk\builds\ directory and a folder for each project being created within that. This is exactly what I want (and keeps my trunk organized and clean). However, upon opening the solution file in VS2013, a folders for my SourceCode directories are automatically created along with bin and obj folders but they aren't used for anything at all. As far as I can tell, it's because of the Link elements being added to the project files.

Kevin Pick
  • 21
  • 3

2 Answers2

0

Usually Visual Studio insists that you keep your C# sources underneath your project directory. A good test would be try to create the same project layout manually in Visual Studio; it should create the same <Link> elements. If it doesn't, your best bet would probably be to open a new issue ticket with a quick description of how the Visual Studio markup differs from what Premake is generating.

Sorry, let me edit that to be more clear: the default files that Visual Studio creates (i.e. when you choose File > New Project…) are always in the same directory as the project file, or in a subdirectory of that location. If you try to add a new file to the project, VS will always place it in a folder underneath the project as well. In that case, no <Link> element is needed.

MyProject/MyProject.csproj
MyProject/src/Hello.cs  <--- in or under project directory, no link needed

You are trying to place your source files in a directory above the project file location.

MyProject/build/MyProject.csproj
MyProject/src/Hello.cs <--- not in or under project directory, needs link

If you move your src/ folder underneath the project file location, Premake will not add the <Link> element. And if you try to create the same layout--src/ located outside of the project directory--in Visual Studio, you'll find that it adds <Link> elements itself.

J. Perkins
  • 3,873
  • 2
  • 29
  • 42
  • When I create a solution and projects in VS2013 just using the default file locations, Link elements are not added to the project files. I should note that at my previous job, we organized our trunk exactly the same way I am doing it now and we did not have this problem. I believe we were using version 1 (just "premake") but I can't be 100% sure about this. I can live with it for now since the builds folder is just a temp folder that never gets checked in. It just causes my OCD to flare up. – Kevin Pick Aug 03 '15 at 16:28
  • As far as i can tell, the Link elements are what prompts the autocreation of the src folders upon opening the solution in VS. I find it odd though that those folders aren't used for anything. – Kevin Pick Aug 03 '15 at 18:58
  • Also, those Link elements are being created by premake. If I delete them from the project files, they empty src folders aren't created, even if I open the solution, make changes, close (and save) and reopen. So, the requirement that source files be located beneath the solution/projects is more of a suggestion :) – Kevin Pick Aug 03 '15 at 20:05
0

I solved this by modifying vs2005_csproj.lua (and running 'premake5 embed' and then rebuilding premake). I added an "if _ACTION" condition at line 180.

if external then
--Change by Kpick, this is not needed (at least for vs2013)
    if _ACTION < "vs2013" then
        _p(3,'<Link>%s</Link>', path.translate(link))
    end
end

I should add that I haven't verified if the Link element is needed at all for any version of VS. I just know it's NOT needed for vs2013 and I didn't want to modify the source code any more than I had to.

Kevin Pick
  • 21
  • 3