ligershark / psbuild Goto Github PK
View Code? Open in Web Editor NEWThis project aims to make using MSBuild easier from powershell
License: Apache License 2.0
This project aims to make using MSBuild easier from powershell
License: Apache License 2.0
We should add a new function Update-Psbuild which will just executes the install instructions from https://github.com/ligershark/psbuild/.
Since I was just learning appveyor I configured the build in the website directly. Now that I have everything configured I will move the config into appveyor.yml
so that it's versioned with the code.
When authoring msbuild files you often need to escape special characters. It'd be helpful to have a function,Get-MSBuildEscapeCharacters
, that can be called to show the common escape characters.
Add support for /clp
to Invoke-MSBuild
. It should default to values which are best practices.
I currently have some PS functions like this:
Function Build { &'msbuild' /nologo /v:q }
Function Clean { &'msbuild' /t:Clean /nologo /v:q }
I was going to replace them with PSBuild; but it doesn't currently work without passing a project. With my functions, I can just type "build" in the root of my repo (which generally has a single .sln
file), but PSBuild doesn't support this.
PSBuild should support the same; if I call Invoke-MSBuild
with no project, call MSBuild anyway, and let it decide what to do.
After building the project it would be nice if we could inspect the resulting project file. To facilitate this let's add a -debugMode
switch to Invoke-MSBuild
that will use the MSBuild APIs to invoke the build and then return the build result as well as resulting ProjectInstance
.
Since we will be calling the APIs instead of the command line we may not be able to understand all the properties but known ones should be passed in.
On the Inovke-MSBuild
function we should enable the -whatif
switch.
Having all three loggers always write to disk can slow a build considerably.
For the CLP parameter we should pass in the property ShowCommandLine
We should add a parameter to Invoke-MSBuild
for /m.
We should add psbuild to psget so that users can easily acquire psbuild.
We should add a parameter to Get-MSBuild which can be used to control the bitness of the version that is returned. The default should be 32 bit.
When psbuild is installed we should add it to the nuget profile as well that way a VS user can easily use this from the package manager console.
We should make sure that the CI server executes the PowerShell test cases under the tests\
folder. We should wait for #38 to be completed. In addition to this we should update build.ps1 to execute the PS test cases. Perhaps we can add a parameter(s) to build.ps1
that just executes the test cases. That way we can use that both locally as well as in CI.
If the build fails we should throw an exception so that the rest of the process after the build can stop.
When Invoke-MSBuild is called with the -debugMode flag at the end of the build we should save the resulting ProjectInstance to a file. We can use the log folder as the location to persist that file. We should perhaps have an options/parameter for that.
After persisting this to disk we should also keep track of this path in the buildResult object which is saved for later use.
Then we can create the following cmdlets / advanced functions
This can be achieved with $projectInstance.ToProjectRootElement().Save('<path>')
When Invoke-MSBuild is called with -debugMode we should keep the last build result. When Invoke-MSBuild is called again (with or without -debugMode) we should re-set that value to either the new result or null.
After we save this value we can create the following cmdlets. These would be an alternative to assigning the result to a var and accessing via instance methods.
Note: We should ensure that these are not confused with the existing "construction" related advanced functions.
We should be able to pipe the project to these cmdlets as well. Using the last build result should be the default.
I don't like having to use a browser to search for the exact name of reserved properties. We should create a function to display the reserved properties and their values for a dummy project.
When invoking msbuild.exe you can pass in parameters on the command line. These parameters are _overriding_ standard property declarations in the project file. In some cases it would be nice to be able to set the _default value_ for a property, i.e. the value that should be used if no other value has been specified. Since msbuild.exe doesn't support this we will have to build it ourselves.
We should add a new parameter to the Invoke-MSBuild
function that allows the user to pass in these properties. This property should be named defaultProperties
.
MSBuild doesn't have the concept of default properties but when MSBuild encounters a declaration like $(PropName)
if the property has not been declared MSBuild will fall back to returning the value of an env var with the same name if it exists. We can exploit this behavior to implement default properties. Inside of Invoke-MSBuild
before we call msbuild.exe we can set the default properties as env variables. If there is any clean up needed we can do that after msbuild.exe returns.
We should add a function Import-Pester
which will download pester from nuget and load the module. This will make it easier to avoid placing pester in repositories.
See the changes aspnet/vsweb-publish@566f311#diff-f0e02e42e53ec40f5d3b8bed031ad09e
Suppose the following:
Invoke-MSBuild $slnFile -properties $msbuildProperties -Verbose -nologfiles
After the build, I see
>>>> Build completed you can use Open-PSBuildLog to open the log file
It should just say
>>>> Build completed
We should add a parameter for Configuration on Invoke-MSBuild
please how to write :
msbuild MyProject.csproj /p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=WMyProject
The user may have a few different intentions when calling Invoke-MSBuild
.
Each of these are mutually exclusive. We should add some parameter sets to Invoke-MSBuild to reflect this. The default parameter set should be Build a file.
I've used the functions below on several projects where psbuild is used. It would be easier to add this to the psbuild.psm1
directly.
Note: we should investigate if the names of the functions below are what we want to use
function Filter-String{
[cmdletbinding()]
param(
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$message
)
process{
foreach($msg in $message){
if($nugetApiKey){
$msg = $msg.Replace($nugetApiKey,'REMOVED-FROM-LOG')
}
$msg
}
}
}
function Write-Message{
[cmdletbinding()]
param(
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$message
)
process{
Filter-String -message $message | Write-Verbose
}
}
<#
.SYNOPSIS
If nuget is in the tools
folder then it will be downloaded there.
#>
function Get-Nuget{
[cmdletbinding()]
param(
$toolsDir = ("$env:LOCALAPPDATA\LigerShark\tools\"),
$nugetDownloadUrl = 'http://nuget.org/nuget.exe'
)
process{
$nugetDestPath = Join-Path -Path $toolsDir -ChildPath nuget.exe
if(!(Test-Path $nugetDestPath)){
$nugetDir = ([System.IO.Path]::GetDirectoryName($nugetDestPath))
if(!(Test-Path $nugetDir)){
New-Item -Path $nugetDir -ItemType Directory | Out-Null
}
'Downloading nuget.exe' | Write-Message
(New-Object System.Net.WebClient).DownloadFile($nugetDownloadUrl, $nugetDestPath)
# double check that is was written to disk
if(!(Test-Path $nugetDestPath)){
throw 'unable to download nuget'
}
}
# return the path of the file
$nugetDestPath
}
}
Configuration
can be set with a direct command-line parameter rather than through properties
, presumably because it is in all sln/csproj files and usually needs to be specified for msbuild.
By the same logic, there should be such a Platform
variable as well.
We should add the following properties as parameters
When building with psbuild you should get a better experience when using appveyor. For example.
Invoke-MSBuild
We should update the non-beta release on nuget, and unlist 0.0.1
If I specify
Invoke-MSBuild $slnFile -msbuildPath $msbuildPath -properties $msbuildProperties -Verbose
I should not see the following warning in my console, especially not in a different color:
Using msbuild.exe from [C:\Program Files (x86)\MSBuild\12.0\bin\amd64\msbuild.exe]. Use Set-MSBuild to change this.
We should add support for generating a log that is written in markdown. Along with this change we should do a few more things, they are listed below.
Open-PSBiuldLog
to have switches for which log should be opened.GetPsBuild.ps1
script pulls from github. It would be better if this pulled from nuget.org instead. This will allow give us a lot of benefits like; versioning, easier testing, and some other stuff.Open-PSBuildLog
to support a switch for which type of log should be openedAdd VisualStudioVersion parameter
When invoking Open-PSbuildLog
you get an error related to indexing an empty array.
We should add a function (and perhaps a param on Invoke-MSBuild) to import VS variables. You can see how to do that at https://github.com/cliffburger/posh-msbuild/blob/master/posh-msbuild.psm1#L62. The only issue with that is that it requires VS to be installed, a portable version of that would be better.
The test cases are no longer current and are failing. We should make the following changes.
build.ps1
to execute the test casesDefault to /m
Invoking a sample console application .sln file using Invoke-MSBuild
throws an error but compiles the project successfully and produces valid .exe.
Invoke-MSBuild .\ConsoleApplication.sln
Exception calling "Open" with "2" argument(s): "The project file could not be loaded. Data at the root level is
invalid. Line 2, position 1. C:\.\ConsoleApplication.sln"
At C:\..\Modules\psbuild\psbuild.psm1:870 char:13
+ $project = ([Microsoft.Build.Construction.ProjectRootElement]::Open( ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidProjectFileException
Add Open-PSBuildLog
which can be used to open the last log file in the default system editor.
We should add the ability to turn off logging, both globally and for a single invocation of Invoke-MSBuild.
-noLogFiles
parameter to Invoke-MSBuild
to avoid loggingAdd Configuration parameter to Invoke-MSBuild. When passed in we should just convert it to an MSBuild property to msbuild.exe.
We can have a better story around NuGet and the package manager console using psbuild. The following are some user statements.
We should add a parameter to Invoke-MSBuild
for /version.
$svnToolFolder = "C:\Program Files\TortoiseSVN\bin\"
$msbuildProperties = @{'SVNToolFolder'=$svnToolFolder;}
Invoke-MSBuild $slnFile -properties $msbuildProperties
As the point of the hashtable is to abstract away the command line, $svnToolFolder should automatically handle arguments with spaces. But this is what I see:
VERBOSE: Performing the operation "Invoke-MSBuild" on target "
msbuild.exe ..\Solutions\MySoliton.sln /p:SVNToolFolder=C:\Program Files\TortoiseSVN\bin\ [...]
We should add a parameter to Invoke-MSBuild
for /nologo.
Get-PSBuildLog returns one or more .log file and Open-PSBuildLog file opens the last .log file. One has to type two commands to open the log file. Can we have Open-PSBuildLog cmdlet accept pipeline object from Get-PSBuildLog.
Get-PSBuildLog | Open-PSBuildLog
With parameter defaults we can directly open the first log file just like it works right now.
We should update build.ps1
so that it can publish to nuget.org. We should also update the CI build to publish to nuget.org whenever the release
branched has a new set of changes.
When Invoke-MSBuild is called with the -debugMode flag we return the resulting ProjectInstance
object. Users can use that object to then execute specific build targets. We could do the following to help here.
We should add a parameter to Invoke-MSBuild
for /preprocess. This could be helpful when working on MSBuild script inside of VS.
We should add a parameter to Invoke-MSBuild
for /detailedsummary.
We should create a nuget package which can be used by other nuget packages to manipulate msbuild files.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.