Visual Studio 2015 Update 3 e .NET Core 1.0 sono finalmente disponibili. Trovate tutti i dettagli al seguente post sul blog di Visual Studio:
Xamarin, framework di sviluppo per applicazioni mobile usando il .Net Framework, è stato appena acquistato da Microsoft. Trovate tutti i dettagli dell’acquisizione qui:
Finalmente! Visual Studio “15” Preview è finalmente disponibili. Tutti i dettagli e come scaricarlo sono qui:
Qualche giorno fa ho tenuto questa sessione ad Ancona per DevMarche. Qui potete trovare le slide:
MacInCloud, azienda che consente il noleggio di macchine Mac, consente anche l’acquisto di un build agent compatibile con Visual Studio Team Services. Se siete interessati, trovate prezzi e configurazione qui:
Di seguito trovate la mia intervista TecHeroes a Future Decoded 2015
In this blog post is explained how to write in multiple files using Powershell. To achieve this purpose, we are going to use message streams, which we have already seen in the previous post: do no use write-host cmdlet.
Streams are a fundamental feature in a scripting language that supports piping such as Powershell, especially to avoid that cmdlet receive messages instead of what they really expect. An interesting reading about this topic is: http://blogs.technet.com/b/heyscriptingguy/archive/2014/03/30/understanding-streams-redirection-and-write-host-in-powershell.aspx
In the following sample, we are going to write in different files based on the output type:
- Log.txt: Write-Host and the Output stream (Write-Output);
- Warning.txt: Warning stream (Write-Warning);
- Error.txt: Error stream (Write-Error).
In lines 16 and 18, Write-Warning and Write-Error messages are sent to the Output stream using redirection operators (2>&1, 3>&1). Each stream and all data related to Write-Host, is written in Log.txt file by “*>” operator when is run (line 24).
The trick to write in multiple files is to use the Tee-Object, which saves data in lines 16 and 18 and send it to the specified file.
More about redirection: https://technet.microsoft.com/it-it/library/Hh847746.aspx
More about Tee-Object: https://technet.microsoft.com/en-us/library/hh849937.aspx
Again: do not use write-host cmdlet! This isn’t something reckless, but there’s a good explanation about this statement. First, if you use Powershell, you need to understand a basic concept:
Powershell is about automation
This means that Powershell scripts need to be write thinking about automation. And for this reason, Write-Host does not have nothing in common with automation. To understand why, we need to investigate on how Write-Host works. To get started, Powershell has many message streams:
To write inside these streams, we can use the following cmdlets (based on the previous list):
So, Write-Host is not related to any stream! This means that Write-Host log directly onto the console. And this is the only reason you should use it. If you need to create a script that is interactive or is ran into the console manually, then we could use it. Jeffrey Snover, Powershell’s father, in the article linked at the bottom, suggests to use it only in throw away scripts. Otherwise, is suggested to use Write-Output. Instead, if we would like to let the user choose what information he wants to see, you could use Write-Verbose.
Following, an example to understand how Write-Host works:
Inside log.txt file we can find just the output of Write-Output. Of course, we can cheat and use Write-Messages *> C:\Temp\log.txt. This way, we use redirection operator to force all outputs to be in the file (note: I’ve tested this only in PS 5). But if you want my 2 cents: don’t do it! Besides, also Write-Output can write in the console! The main difference is that information will be send through stream (as object) and could be used through piping. If Write-Output is the last cmdlet, then information will be sent to the console. One missing feature could be the output formatting, but using a bit of creativity we can use the following cmdlet (the idea came from Stack-Overflow: http://stackoverflow.com/questions/4647756/is-there-a-way-to-specify-a-font-color-when-using-write-output):
Write-Host considered harmful: http://www.jsnover.com/blog/2013/12/07/write-host-considered-harmful/
A lot of very interesting best pratices for Hyper-V backups.