Skip to content

Commit

Permalink
nuget: install cmdlets into VS Package Manager Console
Browse files Browse the repository at this point in the history
  • Loading branch information
max-ieremenko committed Nov 1, 2018
1 parent fd248d4 commit ccd59bf
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 12 deletions.
51 changes: 47 additions & 4 deletions Build/build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
PackageVersion: version of the package, according to myget
nuget: path to nuget.exe
-->

<!-- working directory of msbuild is root\build -->
<BuildOut>..\build.out</BuildOut>
<BuildOut>$(MSBuildProjectDirectory)\..\build.out</BuildOut>
</PropertyGroup>

<Target Name="main">
Expand All @@ -20,6 +20,8 @@

<CallTarget Targets="buildSources"
ContinueOnError="false" />
<CallTarget Targets="setPowerShellModuleVersion"
ContinueOnError="false" />
<CallTarget Targets="buildPackage"
ContinueOnError="false" />
</Target>
Expand All @@ -28,7 +30,7 @@
<Exec Command="$(nuget) restore ..\Sources\SqlDatabase.sln" />

<MSBuild Projects="..\Sources\SqlDatabase.sln"
Properties="Configuration=$(config);OutDir=..\$(BuildOut)"/>
Properties="Configuration=$(config);OutDir=$(BuildOut)"/>

<!--https://stackoverflow.com/questions/443188/msbuild-task-to-read-version-of-dll-->
<GetAssemblyIdentity AssemblyFiles="$(BuildOut)\SqlDatabase.exe">
Expand All @@ -43,7 +45,48 @@
</CreateProperty>
</Target>

<Target Name="setPowerShellModuleVersion">
<ReplaceTextInFile Filename="$(BuildOut)\SqlDatabase.PowerShell.psd1"
MatchText="{{ModuleVersion}}"
ReplacementText="$(PackageVersion)" />
</Target>

<Target Name="buildPackage">
<Exec Command="$(nuget) pack ..\package.nuspec -NoPackageAnalysis -verbosity detailed -OutputDirectory $(BuildOut) -Version $(PackageVersion) -p Configuration=$(config))" />
<Exec Command="$(nuget) pack ..\Sources\SqlDatabase.Package\package.nuspec -NoPackageAnalysis -verbosity detailed -OutputDirectory $(BuildOut) -Version $(PackageVersion) -p bin=$(BuildOut)" />
</Target>

<UsingTask TaskName="ReplaceTextInFile"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<Filename ParameterType="System.String"
Required="true" />
<MatchText ParameterType="System.String"
Required="true" />
<ReplacementText ParameterType="System.String"
Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text" />
<Code Type="Fragment"
Language="cs">
<![CDATA[
var text = new StringBuilder();
Encoding fileEncoding;
using (var reader = new StreamReader(Filename))
{
text.Append(reader.ReadToEnd());
fileEncoding = reader.CurrentEncoding;
}
text.Replace(MatchText, ReplacementText);
File.WriteAllText(Filename, text.ToString(), fileEncoding);
]]>
</Code>
</Task>
</UsingTask>
</Project>
4 changes: 2 additions & 2 deletions Sources/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]

[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
16 changes: 16 additions & 0 deletions Sources/SqlDatabase.Package/SqlDatabase.Package.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<CodeAnalysisRuleSet>..\StyleCope.ruleset</CodeAnalysisRuleSet>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\SqlDatabase.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\GlobalAssemblyInfo.cs" Link="Properties\GlobalAssemblyInfo.cs" />
</ItemGroup>
</Project>
16 changes: 11 additions & 5 deletions package.nuspec → Sources/SqlDatabase.Package/package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@
</metadata>

<files>
<file src="build.out\SqlDatabase.exe"
<file src="tools\**\*"
target="tools/"/>

<file src="$bin$\SqlDatabase.exe"
target="tools" />
<file src="$bin$\SqlDatabase.pdb"
target="tools" />
<file src="build.out\SqlDatabase.pdb"
<file src="$bin$\SqlDatabase.exe.config"
target="tools" />
<file src="build.out\SqlDatabase.exe.config"

<file src="$bin$\SqlDatabase.PowerShell.dll"
target="tools" />
<file src="build.out\SqlDatabase.PowerShell.dll"
<file src="$bin$\SqlDatabase.PowerShell.pdb"
target="tools" />
<file src="build.out\SqlDatabase.PowerShell.pdb"
<file src="$bin$\SqlDatabase.PowerShell.psd1"
target="tools" />
</files>
</package>
23 changes: 23 additions & 0 deletions Sources/SqlDatabase.Package/tools/init.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
param($installPath, $toolsPath, $package, $project)

$activeModule = Get-Module "SqlDatabase.PowerShell"
$thisModule = Join-Path $PSScriptRoot "SqlDatabase.PowerShell.dll"

$import = $true
if ($activeModule)
{
$thisModuleVersion = New-Object -TypeName System.Version (Get-Item $thisModule).VersionInfo.FileVersion
if ($activeModule.Version -le $thisModuleVersion)
{
Remove-Module "SqlDatabase.PowerShell"
}
else
{
$import = $false
}
}

if ($import)
{
Import-Module $thisModule -DisableNameChecking
}
8 changes: 7 additions & 1 deletion Sources/SqlDatabase.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSharpMirationStep", "..\Ex
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlDatabase.PowerShell", "SqlDatabase.PowerShell\SqlDatabase.PowerShell.csproj", "{47A4BE25-2B58-484C-956D-F1DF53A9269D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlDatabase.PowerShell.Test", "SqlDatabase.PowerShell.Test\SqlDatabase.PowerShell.Test.csproj", "{4F35E6D2-99FB-4B7B-90A5-3BFA936FB8CF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlDatabase.PowerShell.Test", "SqlDatabase.PowerShell.Test\SqlDatabase.PowerShell.Test.csproj", "{4F35E6D2-99FB-4B7B-90A5-3BFA936FB8CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SqlDatabase.Package", "SqlDatabase.Package\SqlDatabase.Package.csproj", "{F986789D-F9B3-42B4-AA4B-4C0A63011F5D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -46,6 +48,10 @@ Global
{4F35E6D2-99FB-4B7B-90A5-3BFA936FB8CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F35E6D2-99FB-4B7B-90A5-3BFA936FB8CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F35E6D2-99FB-4B7B-90A5-3BFA936FB8CF}.Release|Any CPU.Build.0 = Release|Any CPU
{F986789D-F9B3-42B4-AA4B-4C0A63011F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F986789D-F9B3-42B4-AA4B-4C0A63011F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F986789D-F9B3-42B4-AA4B-4C0A63011F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F986789D-F9B3-42B4-AA4B-4C0A63011F5D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit ccd59bf

Please sign in to comment.