2016-04-21 07:25:58 +08:00
|
|
|
Where can I learn PowerShell's syntax?
|
|
|
|
======================================
|
|
|
|
|
|
|
|
[SS64.com](http://ss64.com/ps/syntax.html) is a good resource.
|
|
|
|
|
|
|
|
What are the best practices and style?
|
|
|
|
======================================
|
|
|
|
|
|
|
|
The [PoshCode][] unofficial guide is our reference.
|
|
|
|
|
|
|
|
[PoshCode]: https://github.com/PoshCode/PowerShellPracticeAndStyle
|
|
|
|
|
|
|
|
What are PowerShell's scoping rules?
|
|
|
|
====================================
|
|
|
|
|
|
|
|
- Variables are created in your current scope unless explicitly indicated.
|
|
|
|
- Variables are visible in a child scope unless explicitly indicated.
|
|
|
|
- Variables created in a child scope are not visible to a parent unless
|
|
|
|
explicitly indicated.
|
|
|
|
- Variables may be placed explicitly in a scope.
|
|
|
|
|
|
|
|
Things that create a scope:
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
- [functions](http://ss64.com/ps/syntax-functions.html)
|
|
|
|
- [call operator](http://ss64.com/ps/call.html) (`& { }`)
|
|
|
|
- [script invocations](http://ss64.com/ps/syntax-run.html)
|
|
|
|
|
|
|
|
Things that operate in the current scope:
|
|
|
|
-----------------------------------------
|
|
|
|
|
|
|
|
- [source operator](http://ss64.com/ps/source.html) (`. { }`)
|
|
|
|
- [statements](http://ss64.com/ps/statements.html) (`if .. else`, `for`, `switch`, etc.)
|
|
|
|
|
|
|
|
Why didn't an error throw an exception?
|
|
|
|
=======================================
|
|
|
|
|
2016-08-04 16:52:35 +08:00
|
|
|
Error handling in PowerShell is a bit weird, as not all errors result in catchable exceptions by default.
|
|
|
|
Setting `$ErrorActionPreference = 'Stop'` will likely do what you want;
|
2016-08-06 09:36:15 +08:00
|
|
|
that is, cause non-terminating errors instead to terminate.
|
2016-08-04 16:52:35 +08:00
|
|
|
Read [An Introduction To Error Handling in PowerShell][error] for more information.
|
2016-04-21 07:25:58 +08:00
|
|
|
|
|
|
|
[error]: https://blogs.msdn.microsoft.com/kebab/2013/06/09/an-introduction-to-error-handling-in-powershell/
|
|
|
|
|
2016-08-19 01:15:04 +08:00
|
|
|
Where do I get the PowerShell Core SDK package?
|
|
|
|
=============================================================
|
|
|
|
|
|
|
|
The SDK NuGet package `Microsoft.PowerShell.SDK` is provided for developers to write .NET Core C# code targeting PowerShell Core.
|
2016-09-16 12:37:18 +08:00
|
|
|
PowerShell NuGet packages for releases starting from v6.0.0-alpha.9 will be published to the [powershell-core][] myget feed.
|
2016-08-19 01:15:04 +08:00
|
|
|
|
|
|
|
To use the `Microsoft.PowerShell.SDK` NuGet package, declare the `frameworks` section in your `project.json` file as follows:
|
|
|
|
|
|
|
|
```
|
|
|
|
"frameworks": {
|
|
|
|
"netstandard1.6": {
|
|
|
|
"imports": [ "dnxcore50", "portable-net45+win8" ],
|
|
|
|
"dependencies": {
|
2016-09-16 12:37:18 +08:00
|
|
|
"Microsoft.PowerShell.SDK": "1.0.0-alpha10"
|
2016-08-19 01:15:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
[powershell-core]: https://powershell.myget.org/gallery/powershell-core
|
|
|
|
|
2016-07-16 08:30:59 +08:00
|
|
|
Why did my build fail?
|
2016-05-07 01:59:15 +08:00
|
|
|
============================================
|
|
|
|
|
2016-07-16 08:30:59 +08:00
|
|
|
There are few common issues with the build.
|
|
|
|
The easiest way to resolve most issues with the build is to run `Start-PSBuild -Clean`.
|
|
|
|
|
|
|
|
### Dependency changed
|
|
|
|
|
2016-05-07 01:59:15 +08:00
|
|
|
If package dependencies were changed in any `project.json`, you need to manually
|
2016-08-04 16:52:35 +08:00
|
|
|
run `dotnet restore` to update your local dependency graphs.
|
|
|
|
`Start-PSBuild -Restore` can automatically do this.
|
2016-05-07 01:59:15 +08:00
|
|
|
|
2016-07-16 08:30:59 +08:00
|
|
|
### Resource changed
|
|
|
|
|
|
|
|
`Start-PSBuild` automatically calls `Start-ResGen` on the very first run.
|
|
|
|
On subsequent runs, you may need to explicitly use `Start-PSBuild -ResGen` command.
|
|
|
|
|
|
|
|
Try it, when you see compilation error about *strings.
|
|
|
|
|
2016-07-25 13:00:37 +08:00
|
|
|
[More details](dev-process/resx-files.md) about resource.
|
2016-07-16 08:30:59 +08:00
|
|
|
|
|
|
|
### TypeGen
|
|
|
|
|
2016-08-06 09:36:15 +08:00
|
|
|
Similar to `-ResGen` parameter, there is `-TypeGen` parameter that triggers regeneration of type catalog.
|
2016-07-16 08:30:59 +08:00
|
|
|
|
2016-04-21 07:25:58 +08:00
|
|
|
Why did `Start-PSBuild` tell me to update `dotnet`?
|
|
|
|
===================================================
|
|
|
|
|
|
|
|
We depend on the latest version of the .NET CLI, as we use the output of `dotnet
|
2016-08-04 16:52:35 +08:00
|
|
|
--info` to determine the current runtime identifier.
|
|
|
|
Without this information, our build function can't know where `dotnet` is going to place the build artifacts.
|
2016-04-21 07:25:58 +08:00
|
|
|
|
|
|
|
You can automatically install this using `Start-PSBootstrap`.
|
|
|
|
|
|
|
|
**However, you must first manually uninstall other versions of the CLI.**
|
|
|
|
|
2016-08-04 16:52:35 +08:00
|
|
|
If you have installed by using any of the following means:
|
2016-04-21 07:25:58 +08:00
|
|
|
|
2016-08-18 01:06:25 +08:00
|
|
|
- `MSI`
|
2016-04-21 07:25:58 +08:00
|
|
|
- `exe`
|
|
|
|
- `apt-get`
|
|
|
|
- `pkg`
|
|
|
|
|
|
|
|
You *must* manually uninstall it.
|
|
|
|
|
|
|
|
Additionally, if you've just unzipped their binary drops (or used their obtain
|
|
|
|
scripts, which do essentially the same thing), you must manually delete the
|
|
|
|
folder, as the .NET CLI team re-engineered how their binaries are setup, such
|
|
|
|
that new packages' binaries get stomped on by old packages' binaries.
|
|
|
|
|
|
|
|
Why is my submodule empty?
|
|
|
|
==========================
|
|
|
|
|
|
|
|
If a submodule (such as `src/Modules/Pester`) is empty, that means it is
|
2016-08-04 16:52:35 +08:00
|
|
|
uninitialized.
|
|
|
|
If you've already cloned, you can do this with:
|
2016-04-21 07:25:58 +08:00
|
|
|
|
|
|
|
```sh
|
|
|
|
git submodule init
|
|
|
|
git submodule update
|
|
|
|
```
|
|
|
|
|
|
|
|
You can verify that the submodules were initialized properly with:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
git submodule status
|
|
|
|
```
|
|
|
|
|
|
|
|
If they're initialized, it will look like this:
|
|
|
|
|
|
|
|
```
|
|
|
|
f23641488f8d7bf8630ca3496e61562aa3a64009 src/Modules/Pester (f23641488)
|
|
|
|
c99458533a9b4c743ed51537e25989ea55944908 src/libpsl-native/test/googletest (release-1.7.0)
|
|
|
|
```
|
|
|
|
|
2016-08-04 16:52:35 +08:00
|
|
|
If they're not, there will be minuses in front (and the folders will be empty):
|
2016-04-21 07:25:58 +08:00
|
|
|
|
|
|
|
```
|
|
|
|
-f23641488f8d7bf8630ca3496e61562aa3a64009 src/Modules/Pester (f23641488)
|
|
|
|
-c99458533a9b4c743ed51537e25989ea55944908 src/libpsl-native/test/googletest (release-1.7.0)
|
|
|
|
```
|
|
|
|
|
|
|
|
Please note that the commit hashes for the submodules have likely changed since
|
|
|
|
this FAQ was written.
|
|
|
|
|
|
|
|
Why does my submodule say "HEAD detached at" some commit?
|
|
|
|
=========================================================
|
|
|
|
|
|
|
|
When a submodule is first initialized and updated, it is not checked out to a
|
2016-08-06 09:36:15 +08:00
|
|
|
branch, but the very exact commit that the super-project (this PowerShell
|
2016-08-04 16:52:35 +08:00
|
|
|
repository) has recorded for the submodule.
|
2016-08-06 09:36:15 +08:00
|
|
|
This behavior is intended.
|
2016-04-21 07:25:58 +08:00
|
|
|
|
2016-08-04 16:52:35 +08:00
|
|
|
If you want to check out an actual branch, just do so with `git checkout <branch>`.
|
|
|
|
A submodule is just a Git repository; it just happens to be nested inside another repository.
|
2016-04-21 07:25:58 +08:00
|
|
|
|
|
|
|
Please read the Git Book chapter on [submodules][].
|
|
|
|
|
|
|
|
[submodules]: https://git-scm.com/book/en/v2/Git-Tools-Submodules
|
2016-05-05 01:41:49 +08:00
|
|
|
|
|
|
|
Why does AppVeyor say "Project not found or access denied" when opening a build?
|
|
|
|
================================================================================
|
|
|
|
|
2016-08-06 09:36:15 +08:00
|
|
|
This error means you're not signed into AppVeyor.
|
2016-08-04 16:52:35 +08:00
|
|
|
Follow these steps carefully:
|
2016-05-05 01:41:49 +08:00
|
|
|
|
|
|
|
1. Click "SIGN IN" link in upper right corner
|
|
|
|
2. Click the blue "GitHub" button under "Login with your developer account" on the left
|
|
|
|
3. Click the green "Authorize Application" button in the pop-up from GitHub
|
|
|
|
4. Click the "- select account -" menu and choose "PowerShell" (**not** your user)
|
|
|
|
5. Click the blue "GitHub" button below the menu
|
|
|
|
6. Go back to the original link you followed to AppVeyor and click it again
|
|
|
|
|
|
|
|
You should now be signed into AppVeyor and able to access our builds.
|
2016-05-21 07:33:19 +08:00
|
|
|
|
2016-05-25 01:03:45 +08:00
|
|
|
Why did my Travis CI build fail with `GITHUB_TOKEN variable is undefined, please provide token`?
|
|
|
|
================================================================================================
|
|
|
|
|
|
|
|
Travis CI uses an encrypted environment variable to authorize with GitHub and
|
2016-08-04 16:52:35 +08:00
|
|
|
download PowerShell (which it then uses to build and test through the `build.psm1` module).
|
|
|
|
However, the following caveat applies:
|
2016-05-25 01:03:45 +08:00
|
|
|
|
|
|
|
> Encrypted variables are not added to untrusted builds such as pull requests
|
|
|
|
> coming from another repository.
|
|
|
|
|
|
|
|
Thus a pull request made from a fork of the PowerShell repository will not pass
|
2016-08-04 16:52:35 +08:00
|
|
|
the Travis CI as it will be unable to build.
|
|
|
|
Please instead push your branch to the upstream PowerShell repository on GitHub (that is,
|
|
|
|
https://github.com/PowerShell/PowerShell), and issue a new Pull Request.
|
|
|
|
If you cannot do this, please get in contact with us to obtain the necessary permissions.
|