Title: "Using module" statement does not reload module after changes are made · Issue #7654 · PowerShell/PowerShell · GitHub
Open Graph Title: "Using module" statement does not reload module after changes are made · Issue #7654 · PowerShell/PowerShell
X Title: "Using module" statement does not reload module after changes are made · Issue #7654 · PowerShell/PowerShell
Description: Problem Description If you are using the using module statement, it will load the module without any issues. However, if you make a change to the module and run the using module statement again without restarting your PowerShell session,...
Open Graph Description: Problem Description If you are using the using module statement, it will load the module without any issues. However, if you make a change to the module and run the using module statement again wit...
X Description: Problem Description If you are using the using module statement, it will load the module without any issues. However, if you make a change to the module and run the using module statement again wit...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/7654
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"\"Using module\" statement does not reload module after changes are made","articleBody":"Problem Description\r\n------------------\r\nIf you are using the `using module` statement, it will load the module without any issues. However, if you make a change to the module and run the `using module` statement again without restarting your PowerShell session, it will not load the new modified module into memory, and instead will continue to use the old existing module that was loaded. This makes doing development with `using module` statements very tedious as you must continually reload your PowerShell session whenever you make changes to the module.\r\n\r\nIdeally we would just use `Import-Module -Name [module name] -Force` to avoid this issue, but that does not work for importing `class`es, so the `using module` statement **must** be used.\r\n\r\n**Update:** This problem also exists in Windows PowerShell (not Core). Go [here to upvote](https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/35237182--using-module-statement-does-not-reload-module-af) that it gets fixed there too.\r\n\r\nSteps to reproduce\r\n------------------\r\nCreate the following module and script files:\r\n\r\nIn `TestModule.psm1`:\r\n```powershell\r\nclass TestClass \r\n{\r\n\t[string] $ClassPropertyText = \"Initial text\"\r\n}\r\n\r\nfunction Get-ModuleFunctionText()\r\n{\r\n\treturn \"Initial text\"\r\n}\r\n\r\nExport-ModuleMember -Function Get-ModuleFunctionText\r\n```\r\n\r\nIn `Test.ps1`:\r\n```powershell\r\nusing module '.\\TestModule.psm1'\r\n\r\n$instance = [TestClass]::new()\r\n$instance.ClassPropertyText\r\n\r\nGet-ModuleFunctionText\r\n```\r\n\r\nRun `Test.ps1` and it will output:\r\n```\r\nInitial text\r\nInitial text\r\n```\r\n\r\nThen modify `TestModule.psm1` to:\r\n```powershell\r\nclass TestClass \r\n{\r\n\t[string] $ClassPropertyText = \"Updated text\"\r\n}\r\n\r\nfunction Get-ModuleFunctionText()\r\n{\r\n\treturn \"Updated text\"\r\n}\r\n\r\nExport-ModuleMember -Function Get-ModuleFunctionText\r\n```\r\n\r\nRun `Test.ps1` again and it will still output:\r\n```\r\nInitial text\r\nInitial text\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\nWhen running `Test.ps1` the 2nd time, it should output:\r\n```none\r\nUpdated text\r\nUpdated text\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n```powershell\r\n> $PSVersionTable\r\nName Value\r\n---- -----\r\nPSVersion 5.1.17134.228\r\nPSEdition Desktop\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nBuildVersion 10.0.17134.228\r\nCLRVersion 4.0.30319.42000\r\nWSManStackVersion 3.0\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\n```\r\n\r\nAdditional Info\r\n----------------\r\nThe problem can be somewhat reduced by using _both_ the `using module` statement and `Import-Module -Force` statement, like this:\r\n```powershell\r\nusing module '.\\TestModule.psm1'\r\nImport-Module -Name '.\\TestModule.psm1' -Force\r\n\r\n$instance = [TestClass]::new()\r\n$instance.ClassPropertyText\r\n\r\nGet-ModuleFunctionText\r\n```\r\n\r\nThis code would result in the following output:\r\n```\r\nInitial text\r\nUpdated text\r\n```\r\n\r\nSo here the module code was updated, but the `class` code was not.\r\n\r\nProposed Solution\r\n----------------\r\nTo fix this issue I propose adding a `-Force` flag to the `using module` statement that forces the module to be reloaded into memory; the same way that the `-Force` flag works for the `Import-Module` cmdlet. This will allow developing code that uses the `class` construct to work much smoother.","author":{"url":"https://github.com/deadlydog","@type":"Person","name":"deadlydog"},"datePublished":"2018-08-28T23:54:19Z","url":"https://github.com/PowerShell/PowerShell/issues/7654"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:594f6aea-8eca-9812-5ee3-669ac7671cc0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D17A:1B7BAF:195553:247462:6AFDCFA2 |
| html-safe-nonce | 475537376a835a563710bd1b0c5a99180fbc845823f50608defd30048a06eac4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTdBOjFCN0JBRjoxOTU1NTM6MjQ3NDYyOjZBRkRDRkEyIiwidmlzaXRvcl9pZCI6IjMxNTgzMzI3ODU5MTU5NzM1MzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f12981c9ff9aef51d38ebefadc2b8463d3628a44c224bae3286a5b1e826983db |
| hovercard-subject-tag | issue:354945356 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/7654/issue_layout |
| twitter:image | https://opengraph.githubassets.com/494146005f4a331d42d7d92a2f32f68b7191bdcf3c1853256f659efb18d1a60d/PowerShell/PowerShell/issues/7654 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/494146005f4a331d42d7d92a2f32f68b7191bdcf3c1853256f659efb18d1a60d/PowerShell/PowerShell/issues/7654 |
| og:image:alt | Problem Description If you are using the using module statement, it will load the module without any issues. However, if you make a change to the module and run the using module statement again wit... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | deadlydog |
| hostname | github.com |
| expected-hostname | github.com |
| None | 26886a40b582b821a7a76351e0a2f42b6d6160854b6e2520db24f31fd7be5da7 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 68ebaa631a1d248d69ebde4b9c5defd3a19aeb2f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width