+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <ProjectSystemBase>$(MSBuildThisFileDirectory)</ProjectSystemBase>
- <TargetFrameworkAlias Condition=" '$(TargetFrameworkAlias)' == '' ">net45</TargetFrameworkAlias>
- </PropertyGroup>
-
- <PropertyGroup Condition=" '$(TargetFrameworkAlias)' == 'net45' ">
- <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
- <TargetFrameworkMoniker>$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)</TargetFrameworkMoniker>
- </PropertyGroup>
-
- <PropertyGroup Condition=" '$(TargetFrameworkAlias)' == 'netcoreapp1.0' ">
- <TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
- <TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
- <TargetFrameworkMoniker>$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)</TargetFrameworkMoniker>
- </PropertyGroup>
-
- <PropertyGroup>
- <Name>$(MSBuildProjectName)</Name>
- <RootNamespace>$(Name)</RootNamespace>
- <AssemblyName>$(Name)</AssemblyName>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <OutputType>Library</OutputType>
- <OutputPath>bin\$(Configuration)\$(TargetFrameworkAlias)</OutputPath>
- </PropertyGroup>
-
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>true</Optimize>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
-
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
-
-</Project>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-
- <ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">
- <Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
- <Reference Include="System.Data" />
- <Reference Include="System.Net.Http" />
- <Reference Include="System.Xml" />
- </ItemGroup>
-
- <PropertyGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">
- <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
- <NoWarn>$(NoWarn);1701;1702</NoWarn>
- </PropertyGroup>
-
- <PropertyGroup>
- <AdditionalLibPaths>$(CoreFxPath);$(DotnetAssemblyPath)</AdditionalLibPaths>
- </PropertyGroup>
-
- <ItemGroup Condition=" '$(CoreFxPath)' != '' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">
- <CoreFXDir Include="$(CoreFxPath)" Condition="Exists('$(CoreFxPath)')" />
- <CoreFXAssemblies Include="@(CoreFXDir->'%(FullPath)/*.dll')" Exclude="@(CoreFXDir->'%(FullPath)/mscorlib.dll')" />
- <ReferencePath Include="@(CoreFXAssemblies->'%(Filename).dll')" />
- </ItemGroup>
-
- <ItemGroup Condition=" '$(DotnetAssemblyPath)' != '' ">
- <DotnetAssemblyDir Include="$(DotnetAssemblyPath)" Condition="Exists('$(DotnetAssemblyPath)')"/>
- <DotnetAssemblies Include="@(DotnetAssemblyDir->'%(FullPath)/*.dll')"/>
- <ReferencePath Include="@(DotnetAssemblies->'%(Filename).dll')"/>
- </ItemGroup>
-
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-
- <PropertyGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' ">
- <!-- https://github.com/dotnet/corefxlab/tree/master/samples/NetCoreSample and
- https://docs.microsoft.com/en-us/dotnet/articles/core/tutorials/target-dotnetcore-with-msbuild
- -->
- <!-- We don't use any of MSBuild's resolution logic for resolving the framework, so just set these two
- properties to any folder that exists to skip the GetReferenceAssemblyPaths task (not target) and
- to prevent it from outputting a warning (MSB3644).
- -->
- <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory)</_TargetFrameworkDirectories>
- <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>
- <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
- </PropertyGroup>
-
-</Project>
\ No newline at end of file
import sys
import os
-import shutil
import argparse
import subprocess
-import json
import xml.etree.ElementTree as ET
-SCRIPTDIR = os.path.dirname(os.path.realpath(__file__))
-BUILD_TEMPLATE_CSPROJ = os.path.join(SCRIPTDIR, "build-template.csproj")
-BUILD_GENERATED_CSPROJ = "__Autogenerated_Project.Targets"
NUGET_EXE = "/usr/bin/nuget.exe"
-TARGET_FRAMEWORK_NETCOREAPP = "netcoreapp1.0"
+def cmd_pack2(args):
+ nuspec = args.targets[0]
+ tmpfile = nuspec + ".autogenerated.nuspec"
+ if os.path.isfile(nuspec):
+ elPackage = ET.parse(nuspec).getroot()
+ elFiles = elPackage.find("files")
+ if elFiles is None:
+ elFiles = ET.Element("files")
+ for root, dirnames, filenames in os.walk(args.PackageFiles):
+ for file in filenames:
+ if file.endswith(".dll"):
+ fw = os.path.basename(root)
+ elFile = ET.Element("file", {"src": os.path.join(fw, file), "target": "lib/" + fw})
+ elFiles.append(elFile)
+ elPackage.append(elFiles)
+ tree = ET.ElementTree(elPackage)
+ tree.write(tmpfile, encoding = "utf-8", xml_declaration = True)
+ cmd = ["mono", NUGET_EXE, "pack", tmpfile,
+ "-BasePath", args.PackageFiles, "-Version", args.PackageVersion]
+ print " ".join(cmd)
+ subprocess.check_call(cmd)
-def find_output(asm, framework):
- confs = ["Release", "Debug"]
- for conf in confs:
- asmfile = os.path.join(asm, "bin", conf, framework, asm + ".dll")
- if os.path.isfile(asmfile):
- return asmfile
- return None
-
-def parse_project_json(asm):
- jsonfile = os.path.join(asm, 'project.json')
- jsondata = None
- if os.path.isfile(jsonfile):
- fp = open(jsonfile)
- jsondata = json.load(fp)
- fp.close()
- return jsondata
-
-def get_frameworks(asm):
- frameworks = []
- obj = parse_project_json(asm)
- if obj is not None and "frameworks" in obj:
- frameworks = obj["frameworks"]
- return frameworks
-
-def convert_build_options(obj):
- elPropertyGroup = ET.Element("PropertyGroup")
-
- if "keyFile" in obj:
- elSignAssembly = ET.Element("SignAssembly")
- elSignAssembly.text = "true"
- elPropertyGroup.append(elSignAssembly)
- elAssemblyOriginatorKeyFile = ET.Element("AssemblyOriginatorKeyFile")
- elAssemblyOriginatorKeyFile.text = obj["keyFile"]
- elPropertyGroup.append(elAssemblyOriginatorKeyFile)
-
- if "allowUnsafe" in obj:
- elAllowUnsafeBlocks = ET.Element("AllowUnsafeBlocks")
- elAllowUnsafeBlocks.text = str(obj["allowUnsafe"])
- elPropertyGroup.append(elAllowUnsafeBlocks)
-
- return elPropertyGroup
-
-def convert_compile_items(target):
- elItemGroup = ET.Element("ItemGroup")
-
- for root, dirnames, filenames in os.walk(target):
- if not root.startswith(os.path.join(target, "obj")):
- for filename in filenames:
- if filename.endswith(".cs"):
- elCompile = ET.Element("Compile", {"Include" : os.path.join(os.path.relpath(root, target), filename)})
- elItemGroup.append(elCompile)
-
- return elItemGroup
-
-def convert_project_json(target, obj):
- elProject = ET.Element("Project", {"xmlns": "http://schemas.microsoft.com/developer/msbuild/2003"})
-
- if "buildOptions" in obj:
- elBuildOptions = convert_build_options(obj["buildOptions"])
- elProject.append(elBuildOptions)
-
- if os.path.isdir(target):
- elCompileItems = convert_compile_items(target)
- elProject.append(elCompileItems)
-
- return elProject
-
-def ready_csproj(asm, csproj):
- obj = parse_project_json(asm)
- elProject = convert_project_json(asm, obj)
- tree = ET.ElementTree(elProject)
- tree.write(os.path.join(asm, BUILD_GENERATED_CSPROJ), encoding = "utf-8", xml_declaration = True)
- shutil.copy(BUILD_TEMPLATE_CSPROJ, csproj)
-
-def build(csproj, framework, args):
- if framework == TARGET_FRAMEWORK_NETCOREAPP and args.CoreFxPath is None:
- return
-
- cmd = ["xbuild", csproj, "/p:TargetFrameworkAlias=" + framework]
-
- if args.Configuration is not None:
- cmd.append("/p:Configuration=" + args.Configuration)
-
- if args.CoreFxPath is not None:
- cmd.append("/p:CoreFxPath=" + args.CoreFxPath)
-
- if args.DotnetAssemblyPath is not None:
- cmd.append("/p:DotnetAssemblyPath=" + os.path.join(args.DotnetAssemblyPath, "devel", framework))
-
- subprocess.check_call(cmd)
-
-def cmd_build(args):
- for asm in args.targets:
- csproj = os.path.join(asm, asm + ".gbsproj")
- ready_csproj(asm, csproj)
- for fw in get_frameworks(asm):
- build(csproj, fw, args)
-
-def cmd_install(args):
- for asm in args.targets:
- skipRuntimeInstall = False
- for fw in get_frameworks(asm):
- output = find_output(asm, fw)
- if output is not None:
- develdir = os.path.join(args.InstallPath, "devel", fw)
- os.makedirs(develdir)
- shutil.copy(output, develdir)
- if not skipRuntimeInstall:
- shutil.copy(output, args.InstallPath)
- if fw == TARGET_FRAMEWORK_NETCOREAPP:
- skipRuntimeInstall = True
-
-def cmd_pack(args):
- for asm in args.targets:
- nuspec = os.path.join(asm, asm + ".nuspec")
- output = ".nuget"
- if os.path.isfile(nuspec):
- # Ready nuspec file
- if not os.path.isdir(output):
- os.mkdir(output)
- elPackage = ET.parse(nuspec).getroot()
- elFiles = elPackage.find("files")
- if elFiles is None:
- elFiles = ET.Element("files")
- for fw in get_frameworks(asm):
- asmfile = find_output(asm, fw)
- if asmfile is not None:
- nugetfw = "netstandard1.6" if fw == TARGET_FRAMEWORK_NETCOREAPP else fw
- elFile = ET.Element("file", {"src": asmfile, "target": "lib/" + nugetfw})
- elFiles.append(elFile)
- elPackage.append(elFiles)
- tree = ET.ElementTree(elPackage)
- tree.write(os.path.join(output, asm + ".nuspec"), encoding = "utf-8", xml_declaration = True)
- # Packaging
- cmd = ["mono", NUGET_EXE, "pack", os.path.join(output, asm + ".nuspec"),
- "-BasePath", ".", "-Version", args.PackageVersion,
- "-OutputDirectory", output]
- print " ".join(cmd)
- subprocess.check_call(cmd)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
- parser.add_argument("command", choices=["build", "install", "pack"])
+ parser.add_argument("command", choices=["pack"])
parser.add_argument("targets", nargs='+')
- parser.add_argument("--Configuration")
- parser.add_argument("--CoreFxPath")
- parser.add_argument("--DotnetAssemblyPath")
- parser.add_argument("--InstallPath")
parser.add_argument("--PackageVersion")
+ parser.add_argument("--PackageFiles")
args = parser.parse_args()
- if args.command == "build":
- cmd_build(args)
- elif args.command == "install":
- cmd_install(args)
- elif args.command == "pack":
- cmd_pack(args)
+ if args.command == "pack":
+ cmd_pack2(args)
else:
exit(1)