Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a distributable project #25

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
File renamed without changes.
16 changes: 2 additions & 14 deletions XCOM2.targets → assets/XCOM2.targets
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,5 @@
</Target>

<!-- Task definition -->
<UsingTask TaskName="InvokePowershellTask" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<EntryPs1 Required="true" />
<SolutionRoot Required="true" />
<SdkInstallPath Required="true" />
<GameInstallPath Required="true" />
<AdditionalArgs ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="false" />
</ParameterGroup>
<Task>
<Reference Include="System.Management.Automation" />
<Code Language="cs" Source="$(BuildCommonRoot)InvokePowershellTask.cs" />
</Task>
</UsingTask>
</Project>
<UsingTask TaskName="InvokePowershellTask" AssemblyFile="$(BuildCommonRoot)X2ModBuildCommon.dll" />
</Project>
Binary file removed junction.exe
Binary file not shown.
51 changes: 51 additions & 0 deletions package.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
$ErrorActionPreference = "Stop"
Set-StrictMode -Version 3.0
Add-Type -Assembly 'System.IO.Compression.FileSystem'

$junctionVersion = "v1.0.0"
$junctionLink = "https://github.com/robojumper/free-junc/releases/download/$junctionVersion/free-junc.exe.zip"

$myDirectory = Split-Path $MyInvocation.MyCommand.Path
$targetDir = Join-Path -Path $myDirectory "target"
$packageDir = Join-Path -Path $targetDir "package"
$cacheDir = Join-Path -Path $targetDir "cache"

function Ensure-Directory {
[CmdletBinding()]
param ([Parameter(ValueFromPipeline)] [string] $dir)
process {
if (-not (Test-Path $dir)) {
New-Item -Path $dir -ItemType Directory
}
}
}

Ensure-Directory $targetDir
Ensure-Directory $packageDir
Ensure-Directory $cacheDir

$junctionCacheDir = "$cacheDir\free-junc-$($junctionVersion)\"
$junctionZip = "$($junctionCacheDir)free-junc.exe.zip"
$junctionExe = "$($junctionCacheDir)free-junc.exe"

if (-not (Test-Path -Path $junctionZip)) {
Ensure-Directory $junctionCacheDir
Invoke-WebRequest -UseBasicParsing -Uri $junctionLink -OutFile $junctionZip
}

if (-not (Test-Path -Path $junctionExe)) {
[System.IO.Compression.ZipFile]::ExtractToDirectory($junctionZip, $junctionCacheDir)
}

& "MSBuild.exe" ".\src\cs\X2ModBuildCommon.csproj"

if (Test-Path -Path "$packageDir\*") {
Remove-Item -Force -Recurse -Path "$packageDir\*" -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
}

Copy-Item -Force "$myDirectory\LICENSE" "$packageDir\" -WarningAction SilentlyContinue
Copy-Item -Force "$myDirectory\README.md" "$packageDir\" -WarningAction SilentlyContinue
Copy-Item -Force "$junctionExe" "$packageDir\junction.exe" -WarningAction SilentlyContinue
Copy-Item -Force "$cacheDir\X2ModBuildCommon\X2ModBuildCommon.dll" "$packageDir\" -WarningAction SilentlyContinue
Copy-Item -Force "$myDirectory\src\ps\*.ps1" "$packageDir\" -WarningAction SilentlyContinue
Copy-Item -Force "$myDirectory\assets\*" "$packageDir\" -WarningAction SilentlyContinue
File renamed without changes.
32 changes: 32 additions & 0 deletions src/cs/X2ModBuildCommon.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AssemblyName>X2ModBuildCommon</AssemblyName>
<OutputPath>..\..\target\cache\X2ModBuildCommon\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="InvokePowershellTask.cs" />
</ItemGroup>

<Target Name="Build" Inputs="@(Compile)" Outputs="$(OutputPath)$(AssemblyName).dll">
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
<ItemGroup>
<Assemblies Include="System.dll" />
<Assemblies Include="mscorlib.dll" />
<Assemblies Include="Microsoft.Build.Framework.dll" />
<Assemblies Include="Microsoft.Build.Utilities.v4.0.dll" />
<!--<Assemblies Include="System.Management.Automation.dll" />-->
<Assemblies Include="C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll" />
<!--<Assemblies Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll" />-->
<!--<Assemblies Include="C:\WINDOWS\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll" />-->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is the thing I couldn't get to work automatically.

</ItemGroup>
<Csc
Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).dll"
TargetType="Library"
References="@(Assemblies)"
/>
</Target>
<Target Name="Clean" >
<Delete Files="$(OutputPath)$(AssemblyName).dll" />
</Target>
<Target Name="Rebuild" DependsOnTargets="Clean;Build" />
</Project>
File renamed without changes.
File renamed without changes.