[D365] Module reference in model cannot be located
Sometimes it happens on a D365 DevBox that after a get latest or some copy operation in the PackagesLocalDirectory folder the following error occurs after using "Refresh models" in Visual Studio:
Module Reference 'yyy' in model 'zzz' cannot be located. This is an indication that model store is in a broken state.
Most likely this error exists because one of the models has been built with a different update version than the environment that is throwing this error. For example having a model relying on Platform Update 45 functionality and pulling this code into an environment with Platform Update 44, will result in this error.
If the versions match, continue to the following:
Checking the ownership of package folders gives a clue.
The folders of standard packages like ApplicationSuite are owned by a user group
But checking a package folder that is mentioned in the message, it is owned by a user
Out of the many ways to change permissions by hand or scripted, the go-to one for me is
takeown (TechNet Docs) because it can be integrated in automation scripts.
takeown /a /f "C:\AOSService\PackagesLocalDirectory" /r