-- -- vs2005_csproj.lua -- Generate a Visual Studio 2005/2008 C# project. -- Copyright (c) 2009-2010 Jason Perkins and the Premake project -- -- -- Set up namespaces -- premake.vstudio.cs2005 = { } local vstudio = premake.vstudio local cs2005 = premake.vstudio.cs2005 -- -- Figure out what elements a particular source code file need in its item -- block, based on its build action and any related files in the project. -- local function getelements(prj, action, fname) if action == "Compile" and fname:endswith(".cs") then if fname:endswith(".Designer.cs") then -- is there a matching *.cs file? local basename = fname:sub(1, -13) local testname = basename .. ".cs" if premake.findfile(prj, testname) then return "Dependency", testname end -- is there a matching *.resx file? testname = basename .. ".resx" if premake.findfile(prj, testname) then return "AutoGen", testname end else -- is there a *.Designer.cs file? local basename = fname:sub(1, -4) local testname = basename .. ".Designer.cs" if premake.findfile(prj, testname) then return "SubTypeForm" end end end if action == "EmbeddedResource" and fname:endswith(".resx") then -- is there a matching *.cs file? local basename = fname:sub(1, -6) local testname = path.getname(basename .. ".cs") if premake.findfile(prj, testname) then if premake.findfile(prj, basename .. ".Designer.cs") then return "DesignerType", testname else return "Dependency", testname end else -- is there a matching *.Designer.cs? testname = path.getname(basename .. ".Designer.cs") if premake.findfile(prj, testname) then return "AutoGenerated" end end end if action == "Content" then return "CopyNewest" end return "None" end -- -- Write the opening element and project level block. -- function cs2005.projectelement(prj) _p('', iif(_ACTION == 'vs2005', '', ' ToolsVersion="3.5"')) end function cs2005.projectsettings(prj) _p(' ') _p(' %s', premake.esc(prj.solution.configurations[1])) _p(' AnyCPU') _p(' %s', iif(_ACTION == "vs2005", "8.0.50727", "9.0.21022")) _p(' 2.0') _p(' {%s}', prj.uuid) _p(' %s', premake.dotnet.getkind(prj)) _p(' Properties') _p(' %s', prj.buildtarget.basename) _p(' %s', prj.buildtarget.basename) if prj.framework then _p(' v%s', prj.framework) end _p(' ') end -- -- The main function: write the project file. -- function premake.vs2005_csproj(prj) io.eol = "\r\n" local vsversion, toolversion if _ACTION == "vs2005" then vsversion = "8.0.50727" toolversion = nil elseif _ACTION == "vs2008" then vsversion = "9.0.21022" toolversion = "3.5" end if toolversion then _p('', toolversion) else _p('') end _p(' ') _p(' %s', premake.esc(prj.solution.configurations[1])) _p(' AnyCPU') _p(' %s', vsversion) _p(' 2.0') _p(' {%s}', prj.uuid) _p(' %s', premake.dotnet.getkind(prj)) _p(' Properties') _p(' %s', prj.buildtarget.basename) _p(' %s', prj.buildtarget.basename) _p(' ') for cfg in premake.eachconfig(prj) do _p(' ', premake.esc(cfg.name)) if cfg.flags.Symbols then _p(' true') _p(' full') else _p(' pdbonly') end _p(' %s', iif(cfg.flags.Optimize or cfg.flags.OptimizeSize or cfg.flags.OptimizeSpeed, "true", "false")) _p(' %s', cfg.buildtarget.directory) _p(' %s', table.concat(premake.esc(cfg.defines), ";")) _p(' prompt') _p(' 4') if cfg.flags.Unsafe then _p(' true') end if cfg.flags.FatalWarnings then _p(' true') end _p(' ') end _p(' ') for _, ref in ipairs(premake.getlinks(prj, "siblings", "object")) do _p(' ', path.translate(path.getrelative(prj.location, _VS.projectfile(ref)), "\\")) _p(' {%s}', ref.uuid) _p(' %s', premake.esc(ref.name)) _p(' ') end for _, linkname in ipairs(premake.getlinks(prj, "system", "basename")) do _p(' ', premake.esc(linkname)) end _p(' ') _p(' ') for fcfg in premake.eachfile(prj) do local action = premake.dotnet.getbuildaction(fcfg) local fname = path.translate(premake.esc(fcfg.name), "\\") local elements, dependency = getelements(prj, action, fcfg.name) if elements == "None" then _p(' <%s Include="%s" />', action, fname) else _p(' <%s Include="%s">', action, fname) if elements == "AutoGen" then _p(' True') elseif elements == "AutoGenerated" then _p(' Designer') _p(' ResXFileCodeGenerator') _p(' %s.Designer.cs', premake.esc(path.getbasename(fcfg.name))) elseif elements == "SubTypeDesigner" then _p(' Designer') elseif elements == "SubTypeForm" then _p(' Form') elseif elements == "PreserveNewest" then _p(' PreserveNewest') end if dependency then _p(' %s', path.translate(premake.esc(dependency), "\\")) end _p(' ', action) end end _p(' ') _p(' ') _p(' ') _p('') end