2012-01-12 21:59:15 +00:00
|
|
|
--
|
2012-07-23 21:21:06 +00:00
|
|
|
-- vs2005_csproj.lua
|
2013-02-25 15:47:22 +00:00
|
|
|
-- Generate a Visual Studio 2005-2010 C# project.
|
2014-02-08 15:44:57 +00:00
|
|
|
-- Copyright (c) 2009-2014 Jason Perkins and the Premake project
|
2012-07-23 21:21:06 +00:00
|
|
|
--
|
|
|
|
|
2014-02-08 15:44:57 +00:00
|
|
|
local p = premake
|
2017-04-25 05:44:13 +00:00
|
|
|
p.vstudio.cs2005 = {}
|
|
|
|
|
2014-02-08 15:44:57 +00:00
|
|
|
local vstudio = p.vstudio
|
|
|
|
local cs2005 = p.vstudio.cs2005
|
|
|
|
local project = p.project
|
|
|
|
local config = p.config
|
|
|
|
local fileconfig = p.fileconfig
|
|
|
|
local dotnet = p.tools.dotnet
|
2012-07-23 21:21:06 +00:00
|
|
|
|
|
|
|
|
2013-04-25 20:05:08 +00:00
|
|
|
cs2005.elements = {}
|
|
|
|
|
|
|
|
|
2012-07-23 21:21:06 +00:00
|
|
|
--
|
2012-01-12 21:59:15 +00:00
|
|
|
-- Generate a Visual Studio 200x C# project, with support for the new platforms API.
|
2012-07-23 21:21:06 +00:00
|
|
|
--
|
|
|
|
|
2013-04-25 20:05:08 +00:00
|
|
|
cs2005.elements.project = {
|
2014-01-07 22:08:51 +00:00
|
|
|
"xmlDeclaration",
|
2013-04-25 20:05:08 +00:00
|
|
|
"projectElement",
|
2014-12-08 22:42:00 +00:00
|
|
|
"commonProperties",
|
2013-04-25 20:05:08 +00:00
|
|
|
"projectProperties",
|
2013-10-23 17:06:03 +00:00
|
|
|
"configurations",
|
|
|
|
"applicationIcon",
|
2016-03-21 09:12:25 +00:00
|
|
|
"references",
|
2013-04-25 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 15:52:00 +00:00
|
|
|
function cs2005.generate(prj)
|
2015-07-26 22:25:31 +00:00
|
|
|
p.utf8()
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2017-04-25 05:44:13 +00:00
|
|
|
p.callarray(cs2005, cs2005.elements.project, prj)
|
2012-07-23 21:21:06 +00:00
|
|
|
|
2012-08-07 21:03:23 +00:00
|
|
|
_p(1,'<ItemGroup>')
|
2012-07-23 21:21:06 +00:00
|
|
|
cs2005.files(prj)
|
2012-08-07 21:03:23 +00:00
|
|
|
_p(1,'</ItemGroup>')
|
2012-07-23 21:21:06 +00:00
|
|
|
|
2012-10-10 15:09:51 +00:00
|
|
|
cs2005.projectReferences(prj)
|
2013-04-25 20:05:08 +00:00
|
|
|
cs2005.targets(prj)
|
2012-11-28 16:14:47 +00:00
|
|
|
cs2005.buildEvents(prj)
|
|
|
|
|
2014-02-08 15:44:57 +00:00
|
|
|
p.out('</Project>')
|
2012-07-23 21:21:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write the opening <Project> element.
|
|
|
|
--
|
|
|
|
|
2013-04-25 20:05:08 +00:00
|
|
|
function cs2005.projectElement(prj)
|
|
|
|
local ver = ''
|
2017-04-25 05:44:13 +00:00
|
|
|
local action = p.action.current()
|
2013-04-25 20:05:08 +00:00
|
|
|
if action.vstudio.toolsVersion then
|
|
|
|
ver = string.format(' ToolsVersion="%s"', action.vstudio.toolsVersion)
|
|
|
|
end
|
|
|
|
_p('<Project%s DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">', ver)
|
2012-07-23 21:21:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write the opening PropertyGroup, which contains the project-level settings.
|
|
|
|
--
|
|
|
|
|
2013-10-31 15:51:32 +00:00
|
|
|
cs2005.elements.projectProperties = {
|
|
|
|
"configurationCondition",
|
|
|
|
"platformCondition",
|
|
|
|
"productVersion",
|
|
|
|
"schemaVersion",
|
|
|
|
"projectGuid",
|
|
|
|
"outputType",
|
|
|
|
"appDesignerFolder",
|
|
|
|
"rootNamespace",
|
|
|
|
"assemblyName",
|
|
|
|
"targetFrameworkVersion",
|
|
|
|
"targetFrameworkProfile",
|
|
|
|
"fileAlignment",
|
2013-11-15 21:35:27 +00:00
|
|
|
"projectTypeGuids",
|
2013-10-31 15:51:32 +00:00
|
|
|
}
|
2012-07-23 21:21:06 +00:00
|
|
|
|
2013-10-31 15:51:32 +00:00
|
|
|
function cs2005.projectProperties(prj)
|
2012-07-23 21:21:06 +00:00
|
|
|
_p(1,'<PropertyGroup>')
|
|
|
|
local cfg = project.getfirstconfig(prj)
|
2017-04-25 05:44:13 +00:00
|
|
|
p.callarray(cs2005, cs2005.elements.projectProperties, cfg)
|
2013-04-25 20:05:08 +00:00
|
|
|
_p(1,'</PropertyGroup>')
|
|
|
|
end
|
2012-07-23 21:21:06 +00:00
|
|
|
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2013-04-25 20:05:08 +00:00
|
|
|
--
|
2013-10-23 17:06:03 +00:00
|
|
|
-- Write out the settings for the project configurations.
|
2013-04-25 20:05:08 +00:00
|
|
|
--
|
|
|
|
|
2013-10-23 17:06:03 +00:00
|
|
|
cs2005.elements.configuration = {
|
|
|
|
"propertyGroup",
|
|
|
|
"debugProps",
|
|
|
|
"outputProps",
|
|
|
|
"compilerProps",
|
|
|
|
}
|
|
|
|
|
|
|
|
function cs2005.configurations(prj)
|
|
|
|
for cfg in project.eachconfig(prj) do
|
|
|
|
cs2005.configuration(cfg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function cs2005.configuration(cfg)
|
2017-04-25 05:44:13 +00:00
|
|
|
p.callarray(cs2005, cs2005.elements.configuration, cfg)
|
2012-07-23 21:21:06 +00:00
|
|
|
_p(1,'</PropertyGroup>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-09-01 23:28:34 +00:00
|
|
|
function cs2005.dofile(node, cfg, condition)
|
|
|
|
local filecfg = fileconfig.getconfig(node, cfg)
|
|
|
|
if filecfg then
|
|
|
|
local fname = path.translate(node.relpath)
|
|
|
|
|
|
|
|
-- Files that live outside of the project tree need to be "linked"
|
|
|
|
-- and provided with a project relative pseudo-path. Check for any
|
|
|
|
-- leading "../" sequences and, if found, remove them and mark this
|
|
|
|
-- path as external.
|
|
|
|
local link, count = node.relpath:gsub("%.%.%/", "")
|
|
|
|
local external = (count > 0)
|
|
|
|
|
|
|
|
-- Try to provide a little bit of flexibility by allowing virtual
|
|
|
|
-- paths for external files. Would be great to support them for all
|
|
|
|
-- files but Visual Studio chokes if file is already in project area.
|
|
|
|
if external and node.vpath ~= node.relpath then
|
|
|
|
link = node.vpath
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Deduce what, if any, special attributes are required for this file.
|
|
|
|
-- For example, forms may have related source, designer, and resource
|
|
|
|
-- files which need to be associated.
|
|
|
|
|
|
|
|
local info = dotnet.fileinfo(filecfg)
|
|
|
|
|
|
|
|
-- Process any sub-elements required by this file; choose the write
|
|
|
|
-- element form to use based on the results.
|
|
|
|
|
2017-04-25 05:44:13 +00:00
|
|
|
local contents = p.capture(function ()
|
2016-09-01 23:28:34 +00:00
|
|
|
-- Try to write file-level elements in the same order as Visual Studio
|
|
|
|
local elements = {
|
|
|
|
"AutoGen",
|
|
|
|
"CopyToOutputDirectory",
|
|
|
|
"DesignTime",
|
|
|
|
"DependentUpon",
|
|
|
|
"DesignTimeSharedInput",
|
|
|
|
"Generator",
|
|
|
|
"LastGenOutput",
|
|
|
|
"SubType",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, el in ipairs(elements) do
|
|
|
|
local value = info[el]
|
|
|
|
if value then
|
|
|
|
_p(3,"<%s>%s</%s>", el, value, el)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if info.action == "EmbeddedResource" and cfg.customtoolnamespace then
|
|
|
|
_p(3,"<CustomToolNamespace>%s</CustomToolNamespace>", cfg.customtoolnamespace)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
if #contents > 0 or external then
|
|
|
|
_p(2,'<%s%s Include="%s">', info.action, condition, fname)
|
|
|
|
if external then
|
|
|
|
_p(3,'<Link>%s</Link>', path.translate(link))
|
|
|
|
end
|
|
|
|
if #contents > 0 then
|
|
|
|
_p("%s", contents)
|
|
|
|
end
|
|
|
|
_p(2,'</%s>', info.action)
|
|
|
|
else
|
|
|
|
_p(2,'<%s%s Include="%s" />', info.action, condition, fname)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-08-07 21:03:23 +00:00
|
|
|
--
|
|
|
|
-- Write out the source files item group.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs2005.files(prj)
|
2016-09-01 23:28:34 +00:00
|
|
|
local firstcfg = project.getfirstconfig(prj)
|
2013-11-20 20:35:37 +00:00
|
|
|
|
2012-08-07 21:03:23 +00:00
|
|
|
local tr = project.getsourcetree(prj)
|
2017-04-25 05:44:13 +00:00
|
|
|
p.tree.traverse(tr, {
|
2012-08-07 21:03:23 +00:00
|
|
|
onleaf = function(node, depth)
|
2016-09-01 23:28:34 +00:00
|
|
|
-- test if all fileinfo's are going to be the same for each config.
|
|
|
|
local allsame = true
|
|
|
|
local first = nil
|
|
|
|
for cfg in project.eachconfig(prj) do
|
|
|
|
local filecfg = fileconfig.getconfig(node, cfg)
|
|
|
|
local info = dotnet.fileinfo(filecfg)
|
|
|
|
|
|
|
|
if first == nil then
|
|
|
|
first = info
|
|
|
|
elseif not table.equals(first, info) then
|
|
|
|
allsame = false
|
2013-11-20 20:35:37 +00:00
|
|
|
end
|
2016-09-01 23:28:34 +00:00
|
|
|
end
|
2013-06-17 15:46:53 +00:00
|
|
|
|
2016-09-01 23:28:34 +00:00
|
|
|
-- output to csproj.
|
|
|
|
if allsame then
|
|
|
|
cs2005.dofile(node, firstcfg, '')
|
2013-11-20 20:35:37 +00:00
|
|
|
else
|
2016-09-01 23:28:34 +00:00
|
|
|
for cfg in project.eachconfig(prj) do
|
|
|
|
cs2005.dofile(node, cfg, ' ' .. cs2005.condition(cfg))
|
|
|
|
end
|
2012-08-07 21:03:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
}, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-11-28 16:14:47 +00:00
|
|
|
--
|
|
|
|
-- Write out pre- and post-build events, if provided.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs2005.buildEvents(prj)
|
|
|
|
local function output(name, steps)
|
|
|
|
if #steps > 0 then
|
2017-04-18 16:37:29 +00:00
|
|
|
steps = os.translateCommandsAndPaths(steps, prj.basedir, prj.location)
|
2014-01-09 23:06:03 +00:00
|
|
|
steps = table.implode(steps, "", "", "\r\n")
|
|
|
|
_x(2,'<%sBuildEvent>%s</%sBuildEvent>', name, steps, name)
|
2012-11-28 16:14:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-27 18:12:36 +00:00
|
|
|
local cfg = project.getfirstconfig(prj)
|
|
|
|
if #cfg.prebuildcommands > 0 or #cfg.postbuildcommands > 0 then
|
2012-11-28 16:14:47 +00:00
|
|
|
_p(1,'<PropertyGroup>')
|
2014-11-27 18:12:36 +00:00
|
|
|
output("Pre", cfg.prebuildcommands)
|
|
|
|
output("Post", cfg.postbuildcommands)
|
2012-11-28 16:14:47 +00:00
|
|
|
_p(1,'</PropertyGroup>')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-07-23 21:21:06 +00:00
|
|
|
--
|
2012-10-02 16:57:10 +00:00
|
|
|
-- Write the compiler flags for a particular configuration.
|
2012-07-23 21:21:06 +00:00
|
|
|
--
|
|
|
|
|
2012-10-02 16:57:10 +00:00
|
|
|
function cs2005.compilerProps(cfg)
|
|
|
|
_x(2,'<DefineConstants>%s</DefineConstants>', table.concat(cfg.defines, ";"))
|
2012-07-23 21:21:06 +00:00
|
|
|
|
|
|
|
_p(2,'<ErrorReport>prompt</ErrorReport>')
|
|
|
|
_p(2,'<WarningLevel>4</WarningLevel>')
|
|
|
|
|
2014-11-12 00:24:07 +00:00
|
|
|
if cfg.clr == "Unsafe" then
|
2012-07-23 21:21:06 +00:00
|
|
|
_p(2,'<AllowUnsafeBlocks>true</AllowUnsafeBlocks>')
|
|
|
|
end
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2014-02-14 17:23:12 +00:00
|
|
|
if cfg.flags.FatalCompileWarnings then
|
2012-07-23 21:21:06 +00:00
|
|
|
_p(2,'<TreatWarningsAsErrors>true</TreatWarningsAsErrors>')
|
|
|
|
end
|
2015-01-02 22:26:13 +00:00
|
|
|
|
|
|
|
cs2005.debugCommandParameters(cfg)
|
2012-10-02 16:57:10 +00:00
|
|
|
end
|
|
|
|
|
2015-01-02 22:26:13 +00:00
|
|
|
--
|
|
|
|
-- Write out the debug start parameters for MonoDevelop/Xamarin Studio.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs2005.debugCommandParameters(cfg)
|
|
|
|
if #cfg.debugargs > 0 then
|
|
|
|
_x(2,'<Commandlineparameters>%s</Commandlineparameters>', table.concat(cfg.debugargs, " "))
|
|
|
|
end
|
|
|
|
end
|
2012-10-02 16:57:10 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Write out the debugging and optimization flags for a configuration.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs2005.debugProps(cfg)
|
2016-06-22 15:36:42 +00:00
|
|
|
if cfg.symbols == p.ON then
|
2012-10-02 16:57:10 +00:00
|
|
|
_p(2,'<DebugSymbols>true</DebugSymbols>')
|
|
|
|
_p(2,'<DebugType>full</DebugType>')
|
|
|
|
else
|
|
|
|
_p(2,'<DebugType>pdbonly</DebugType>')
|
|
|
|
end
|
2013-09-13 15:15:36 +00:00
|
|
|
_p(2,'<Optimize>%s</Optimize>', iif(config.isOptimizedBuild(cfg), "true", "false"))
|
2012-10-02 16:57:10 +00:00
|
|
|
end
|
2012-07-23 21:21:06 +00:00
|
|
|
|
2012-10-02 16:57:10 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Write out the target and intermediates settings for a configuration.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs2005.outputProps(cfg)
|
2015-05-08 21:08:41 +00:00
|
|
|
local outdir = vstudio.path(cfg, cfg.buildtarget.directory)
|
|
|
|
_x(2,'<OutputPath>%s\\</OutputPath>', outdir)
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-10-02 16:57:10 +00:00
|
|
|
-- Want to set BaseIntermediateOutputPath because otherwise VS will create obj/
|
|
|
|
-- anyway. But VS2008 throws up ominous warning if present.
|
2015-05-08 21:08:41 +00:00
|
|
|
local objdir = vstudio.path(cfg, cfg.objdir)
|
2012-10-02 16:57:10 +00:00
|
|
|
if _ACTION > "vs2008" then
|
2012-10-08 15:50:42 +00:00
|
|
|
_x(2,'<BaseIntermediateOutputPath>%s\\</BaseIntermediateOutputPath>', objdir)
|
2012-10-02 16:57:10 +00:00
|
|
|
_p(2,'<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>')
|
|
|
|
else
|
2012-10-08 15:50:42 +00:00
|
|
|
_x(2,'<IntermediateOutputPath>%s\\</IntermediateOutputPath>', objdir)
|
2012-10-02 16:57:10 +00:00
|
|
|
end
|
2012-07-23 21:21:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-10-10 15:09:51 +00:00
|
|
|
--
|
2016-03-24 18:55:29 +00:00
|
|
|
-- Write out the references item group.
|
2012-10-10 15:09:51 +00:00
|
|
|
--
|
|
|
|
|
2016-03-21 09:12:25 +00:00
|
|
|
cs2005.elements.references = function(prj)
|
|
|
|
return {
|
|
|
|
cs2005.assemblyReferences,
|
|
|
|
cs2005.nuGetReferences,
|
|
|
|
}
|
|
|
|
end
|
2012-10-10 15:09:51 +00:00
|
|
|
|
2016-03-24 18:55:29 +00:00
|
|
|
function cs2005.references(prj)
|
|
|
|
_p(1,'<ItemGroup>')
|
|
|
|
p.callArray(cs2005.elements.references, prj)
|
|
|
|
_p(1,'</ItemGroup>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write the list of assembly (system, or non-sibling) references.
|
|
|
|
--
|
|
|
|
|
2016-03-21 09:12:25 +00:00
|
|
|
function cs2005.assemblyReferences(prj)
|
2012-10-10 15:09:51 +00:00
|
|
|
-- C# doesn't support per-configuration links (does it?) so just use
|
|
|
|
-- the settings from the first available config instead
|
2013-08-11 13:51:19 +00:00
|
|
|
local cfg = project.getfirstconfig(prj)
|
|
|
|
|
|
|
|
config.getlinks(cfg, "system", function(original, decorated)
|
2015-02-14 20:41:41 +00:00
|
|
|
local name = path.getname(decorated)
|
|
|
|
if path.getextension(name) == ".dll" then
|
|
|
|
name = name.sub(name, 1, -5)
|
|
|
|
end
|
|
|
|
|
2013-08-11 13:51:19 +00:00
|
|
|
if decorated:find("/", nil, true) then
|
2015-02-14 20:41:41 +00:00
|
|
|
_x(2,'<Reference Include="%s">', name)
|
2017-03-27 15:45:37 +00:00
|
|
|
local decPath, decVars = decorated:match("(.-),")
|
|
|
|
if not decPath then
|
|
|
|
decPath = decorated
|
|
|
|
end
|
|
|
|
|
|
|
|
_x(3,'<HintPath>%s</HintPath>', path.appendextension(path.translate(decPath), ".dll"))
|
2013-08-11 13:51:19 +00:00
|
|
|
|
|
|
|
if not config.isCopyLocal(prj, original, true) then
|
|
|
|
_p(3,"<Private>False</Private>")
|
|
|
|
end
|
|
|
|
|
2012-10-10 15:09:51 +00:00
|
|
|
_p(2,'</Reference>')
|
|
|
|
else
|
2015-02-14 20:41:41 +00:00
|
|
|
_x(2,'<Reference Include="%s" />', name)
|
2012-10-10 15:09:51 +00:00
|
|
|
end
|
2013-08-11 13:51:19 +00:00
|
|
|
end)
|
2016-03-21 09:12:25 +00:00
|
|
|
end
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2016-03-24 18:55:29 +00:00
|
|
|
|
2017-07-31 13:01:27 +00:00
|
|
|
--
|
|
|
|
-- This is a bit janky. To compare versions, we extract all numbers from the
|
|
|
|
-- given string and right-pad the result with zeros. Then we can just do a
|
|
|
|
-- lexicographical compare on the resulting strings.
|
|
|
|
--
|
|
|
|
-- This is so that we can compare version strings such as "4.6" and "net451"
|
|
|
|
-- with each other.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs2005.makeVersionComparable(version)
|
|
|
|
local numbers = ""
|
|
|
|
|
|
|
|
for number in version:gmatch("%d") do
|
|
|
|
numbers = numbers .. number
|
|
|
|
end
|
|
|
|
|
|
|
|
return string.format("%-10d", numbers):gsub(" ", "0")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- https://github.com/NuGet/NuGet.Client/blob/dev/test/NuGet.Core.Tests/NuGet.Frameworks.Test/NuGetFrameworkParseTests.cs
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs2005.frameworkVersionForFolder(folder)
|
|
|
|
-- If this exporter ever supports frameworks such as "netstandard1.3",
|
|
|
|
-- "sl4", "sl5", "uap10", "wp8" or "wp71", this code will need changing
|
|
|
|
-- to match the right folders, depending on the current framework.
|
|
|
|
|
|
|
|
-- Right now this only matches folders for the .NET Framework.
|
|
|
|
|
|
|
|
if folder:match("^net%d+$") or folder:match("^[0-9%.]+$") then
|
|
|
|
return cs2005.makeVersionComparable(folder)
|
|
|
|
elseif folder == "net" then
|
|
|
|
return cs2005.makeVersionComparable("0")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-03-24 18:48:58 +00:00
|
|
|
--
|
2016-03-24 18:55:29 +00:00
|
|
|
-- Write the list of NuGet references.
|
2016-03-24 18:48:58 +00:00
|
|
|
--
|
|
|
|
|
2016-03-21 09:12:25 +00:00
|
|
|
function cs2005.nuGetReferences(prj)
|
2016-03-21 18:10:28 +00:00
|
|
|
if _ACTION >= "vs2010" then
|
2017-04-07 14:07:17 +00:00
|
|
|
for _, package in ipairs(prj.nuget) do
|
|
|
|
local id = vstudio.nuget2010.packageId(package)
|
2017-04-07 14:25:35 +00:00
|
|
|
local packageAPIInfo = vstudio.nuget2010.packageAPIInfo(prj, package)
|
2017-04-07 14:07:17 +00:00
|
|
|
|
|
|
|
local cfg = p.project.getfirstconfig(prj)
|
2017-04-25 05:44:13 +00:00
|
|
|
local action = p.action.current()
|
2017-04-07 14:07:17 +00:00
|
|
|
local targetFramework = cfg.dotnetframework or action.vstudio.targetFramework
|
|
|
|
|
2017-07-31 13:01:27 +00:00
|
|
|
local targetVersion = cs2005.makeVersionComparable(targetFramework)
|
2017-04-07 14:07:17 +00:00
|
|
|
|
|
|
|
-- Figure out what folder contains the files for the nearest
|
|
|
|
-- supported .NET Framework version.
|
|
|
|
|
|
|
|
local files = {}
|
|
|
|
|
|
|
|
local bestVersion, bestFolder
|
|
|
|
|
|
|
|
for _, file in ipairs(packageAPIInfo.packageEntries) do
|
2017-07-31 13:01:27 +00:00
|
|
|
local folder = file:match("^lib\\(.+)\\")
|
2017-04-07 14:07:17 +00:00
|
|
|
|
|
|
|
if folder and path.hasextension(file, ".dll") then
|
2017-07-31 13:01:27 +00:00
|
|
|
local version = cs2005.frameworkVersionForFolder(folder)
|
2017-04-07 14:07:17 +00:00
|
|
|
|
2017-07-31 13:01:27 +00:00
|
|
|
if version then
|
|
|
|
files[folder] = files[folder] or {}
|
|
|
|
table.insert(files[folder], file)
|
2017-04-07 14:07:17 +00:00
|
|
|
|
2017-07-31 13:01:27 +00:00
|
|
|
if version <= targetVersion and (not bestVersion or version > bestVersion) then
|
|
|
|
bestVersion = version
|
|
|
|
bestFolder = folder
|
|
|
|
end
|
2017-04-07 14:07:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not bestVersion then
|
|
|
|
p.error("NuGet package '%s' is not compatible with project '%s' .NET Framework version '%s'", id, prj.name, targetFramework)
|
2016-03-19 16:23:28 +00:00
|
|
|
end
|
|
|
|
|
2017-04-07 14:07:17 +00:00
|
|
|
-- Now, add references for all DLLs in that folder.
|
|
|
|
|
|
|
|
for _, file in ipairs(files[bestFolder]) do
|
|
|
|
-- There's some stuff missing from this include that we
|
|
|
|
-- can't get from the API and would need to download and
|
|
|
|
-- extract the package to figure out. It looks like we can
|
|
|
|
-- just omit it though.
|
|
|
|
--
|
|
|
|
-- So, for example, instead of:
|
|
|
|
--
|
|
|
|
-- <Reference Include="nunit.framework, Version=3.6.1.0,
|
|
|
|
-- <Culture=neutral, PublicKeyToken=2638cd05610744eb,
|
|
|
|
-- <processorArchitecture=MSIL">
|
|
|
|
--
|
|
|
|
-- We're just outputting:
|
|
|
|
--
|
|
|
|
-- <Reference Include="nunit.framework">
|
|
|
|
|
|
|
|
_x(2, '<Reference Include="%s">', path.getbasename(file))
|
2017-06-20 21:35:53 +00:00
|
|
|
_x(3, '<HintPath>%s</HintPath>', vstudio.path(prj, p.filename(prj.workspace, string.format("packages\\%s.%s\\%s", id, packageAPIInfo.verbatimVersion or packageAPIInfo.version, file))))
|
2017-04-13 10:44:20 +00:00
|
|
|
|
|
|
|
if config.isCopyLocal(prj, package, true) then
|
|
|
|
_p(3, '<Private>True</Private>')
|
|
|
|
else
|
|
|
|
_p(3, '<Private>False</Private>')
|
|
|
|
end
|
|
|
|
|
2017-04-07 14:07:17 +00:00
|
|
|
_p(2, '</Reference>')
|
|
|
|
end
|
2016-03-19 16:23:28 +00:00
|
|
|
end
|
|
|
|
end
|
2016-03-21 09:12:25 +00:00
|
|
|
end
|
2016-03-19 16:23:28 +00:00
|
|
|
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-07-23 21:21:06 +00:00
|
|
|
--
|
|
|
|
-- Write the list of project dependencies.
|
|
|
|
--
|
|
|
|
function cs2005.projectReferences(prj)
|
|
|
|
_p(1,'<ItemGroup>')
|
|
|
|
|
2015-07-14 01:22:44 +00:00
|
|
|
local deps = project.getdependencies(prj, 'linkOnly')
|
2012-09-27 14:15:27 +00:00
|
|
|
if #deps > 0 then
|
|
|
|
for _, dep in ipairs(deps) do
|
2015-05-08 21:08:41 +00:00
|
|
|
local relpath = vstudio.path(prj, vstudio.projectfile(dep))
|
|
|
|
_x(2,'<ProjectReference Include="%s">', relpath)
|
2012-09-27 14:15:27 +00:00
|
|
|
_p(3,'<Project>{%s}</Project>', dep.uuid)
|
|
|
|
_x(3,'<Name>%s</Name>', dep.name)
|
2013-08-11 13:51:19 +00:00
|
|
|
|
|
|
|
if not config.isCopyLocal(prj, dep.name, true) then
|
|
|
|
_p(3,"<Private>False</Private>")
|
|
|
|
end
|
|
|
|
|
2012-09-27 14:15:27 +00:00
|
|
|
_p(2,'</ProjectReference>')
|
|
|
|
end
|
2012-07-23 21:21:06 +00:00
|
|
|
end
|
2013-02-25 15:47:22 +00:00
|
|
|
|
2012-07-23 21:21:06 +00:00
|
|
|
_p(1,'</ItemGroup>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Return the Visual Studio architecture identification string. The logic
|
2013-02-25 15:47:22 +00:00
|
|
|
-- to select this is getting more complicated in VS2010, but I haven't
|
2012-07-23 21:21:06 +00:00
|
|
|
-- tackled all the permutations yet.
|
|
|
|
--
|
|
|
|
|
2012-11-26 19:05:33 +00:00
|
|
|
function cs2005.arch(cfg)
|
|
|
|
local arch = vstudio.archFromConfig(cfg)
|
|
|
|
if arch == "Any CPU" then
|
|
|
|
arch = "AnyCPU"
|
|
|
|
end
|
|
|
|
return arch
|
2012-07-23 21:21:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write the PropertyGroup element for a specific configuration block.
|
|
|
|
--
|
|
|
|
|
2012-11-26 19:05:33 +00:00
|
|
|
function cs2005.propertyGroup(cfg)
|
2016-09-01 23:28:34 +00:00
|
|
|
p.push('<PropertyGroup %s>', cs2005.condition(cfg))
|
|
|
|
|
2012-11-26 19:05:33 +00:00
|
|
|
local arch = cs2005.arch(cfg)
|
|
|
|
if arch ~= "AnyCPU" or _ACTION > "vs2008" then
|
2015-08-20 19:34:23 +00:00
|
|
|
p.x('<PlatformTarget>%s</PlatformTarget>', arch)
|
2012-07-23 21:21:06 +00:00
|
|
|
end
|
|
|
|
end
|
2013-02-25 15:47:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Generators for individual project elements.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs2005.applicationIcon(prj)
|
|
|
|
if prj.icon then
|
2015-05-08 21:08:41 +00:00
|
|
|
local icon = vstudio.path(prj, prj.icon)
|
2013-02-25 15:47:22 +00:00
|
|
|
_p(1,'<PropertyGroup>')
|
|
|
|
_x(2,'<ApplicationIcon>%s</ApplicationIcon>', icon)
|
|
|
|
_p(1,'</PropertyGroup>')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-02 22:26:13 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- Support functions
|
|
|
|
--
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Format and return a Visual Studio Condition attribute.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs2005.condition(cfg)
|
2016-09-01 23:28:34 +00:00
|
|
|
local platform = vstudio.projectPlatform(cfg)
|
|
|
|
local arch = cs2005.arch(cfg)
|
|
|
|
return string.format('Condition=" \'$(Configuration)|$(Platform)\' == \'%s|%s\' "', platform, arch)
|
2015-01-02 22:26:13 +00:00
|
|
|
end
|
2013-04-25 20:05:08 +00:00
|
|
|
|
2016-03-24 18:55:29 +00:00
|
|
|
|
2016-04-07 11:34:41 +00:00
|
|
|
--
|
|
|
|
-- When given a .NET Framework version, returns it formatted for NuGet.
|
|
|
|
--
|
|
|
|
|
|
|
|
function cs2005.formatNuGetFrameworkVersion(framework)
|
|
|
|
return "net" .. framework:gsub("%.", "")
|
|
|
|
end
|
|
|
|
|
2013-04-25 20:05:08 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- Handlers for individual project elements
|
|
|
|
--
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2013-10-31 15:51:32 +00:00
|
|
|
function cs2005.appDesignerFolder(cfg)
|
|
|
|
_p(2,'<AppDesignerFolder>Properties</AppDesignerFolder>')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function cs2005.assemblyName(cfg)
|
|
|
|
_p(2,'<AssemblyName>%s</AssemblyName>', cfg.buildtarget.basename)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-12-08 22:42:00 +00:00
|
|
|
function cs2005.commonProperties(prj)
|
|
|
|
if _ACTION > "vs2010" then
|
|
|
|
_p(1,'<Import Project="$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props" Condition="Exists(\'$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\')" />')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-10-31 15:51:32 +00:00
|
|
|
function cs2005.configurationCondition(cfg)
|
|
|
|
_x(2,'<Configuration Condition=" \'$(Configuration)\' == \'\' ">%s</Configuration>', cfg.buildcfg)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function cs2005.fileAlignment(cfg)
|
2013-04-25 20:05:08 +00:00
|
|
|
if _ACTION >= "vs2010" then
|
|
|
|
_p(2,'<FileAlignment>512</FileAlignment>')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-10-31 15:51:32 +00:00
|
|
|
function cs2005.outputType(cfg)
|
|
|
|
_p(2,'<OutputType>%s</OutputType>', dotnet.getkind(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function cs2005.platformCondition(cfg)
|
|
|
|
_p(2,'<Platform Condition=" \'$(Platform)\' == \'\' ">%s</Platform>', cs2005.arch(cfg.project))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function cs2005.productVersion(cfg)
|
2017-04-25 05:44:13 +00:00
|
|
|
local action = p.action.current()
|
2013-04-25 20:05:08 +00:00
|
|
|
if action.vstudio.productVersion then
|
|
|
|
_p(2,'<ProductVersion>%s</ProductVersion>', action.vstudio.productVersion)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-31 15:51:32 +00:00
|
|
|
function cs2005.projectGuid(cfg)
|
|
|
|
_p(2,'<ProjectGuid>{%s}</ProjectGuid>', cfg.uuid)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-11-15 21:35:27 +00:00
|
|
|
function cs2005.projectTypeGuids(cfg)
|
|
|
|
if cfg.flags.WPF then
|
|
|
|
_p(2,'<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-10-31 15:51:32 +00:00
|
|
|
function cs2005.rootNamespace(cfg)
|
|
|
|
_p(2,'<RootNamespace>%s</RootNamespace>', cfg.namespace or cfg.buildtarget.basename)
|
|
|
|
end
|
|
|
|
|
2013-04-25 20:05:08 +00:00
|
|
|
|
2013-10-31 15:51:32 +00:00
|
|
|
function cs2005.schemaVersion(cfg)
|
2017-04-25 05:44:13 +00:00
|
|
|
local action = p.action.current()
|
2013-04-25 20:05:08 +00:00
|
|
|
if action.vstudio.csprojSchemaVersion then
|
|
|
|
_p(2,'<SchemaVersion>%s</SchemaVersion>', action.vstudio.csprojSchemaVersion)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-10-31 15:51:32 +00:00
|
|
|
function cs2005.targetFrameworkVersion(cfg)
|
2017-04-25 05:44:13 +00:00
|
|
|
local action = p.action.current()
|
2015-09-10 01:58:52 +00:00
|
|
|
local framework = cfg.dotnetframework or action.vstudio.targetFramework
|
2013-04-25 20:05:08 +00:00
|
|
|
if framework then
|
|
|
|
_p(2,'<TargetFrameworkVersion>v%s</TargetFrameworkVersion>', framework)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-10-31 15:51:32 +00:00
|
|
|
function cs2005.targetFrameworkProfile(cfg)
|
2013-04-25 20:05:08 +00:00
|
|
|
if _ACTION == "vs2010" then
|
2013-05-15 15:15:54 +00:00
|
|
|
_p(2,'<TargetFrameworkProfile>')
|
|
|
|
_p(2,'</TargetFrameworkProfile>')
|
2013-04-25 20:05:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function cs2005.targets(prj)
|
|
|
|
local bin = iif(_ACTION <= "vs2010", "MSBuildBinPath", "MSBuildToolsPath")
|
|
|
|
_p(1,'<Import Project="$(%s)\\Microsoft.CSharp.targets" />', bin)
|
|
|
|
_p(1,'<!-- To modify your build process, add your task inside one of the targets below and uncomment it.')
|
|
|
|
_p(1,' Other similar extension points exist, see Microsoft.Common.targets.')
|
|
|
|
_p(1,'<Target Name="BeforeBuild">')
|
|
|
|
_p(1,'</Target>')
|
|
|
|
_p(1,'<Target Name="AfterBuild">')
|
|
|
|
_p(1,'</Target>')
|
|
|
|
_p(1,'-->')
|
|
|
|
end
|
2014-01-07 22:08:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
function cs2005.xmlDeclaration()
|
|
|
|
if _ACTION > "vs2008" then
|
2014-08-11 21:50:55 +00:00
|
|
|
p.xmlUtf8()
|
2014-01-07 22:08:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|