Reputation: 192
I have been working on my first .NET Core console program and am working to make it operate through multiple PowerShell scripts. When manually executing my FileRelocation
program from PowerShell, I go to the appropriate directory and enter the following into the terminal:
dotnet .\FileRelocation.dll [commands for .dll]
This executes without any issue. However, when trying this from a .ps1
file, I am always given the following error:
dotnet : No executable found matching command "dotnet-.\FileRelocation.dll"
At \\chimera\home\freerey\My Documents\C# Projects\File Relocation Program\0.5.1 Beta\scripts\pstest.ps1:2 char:1
+ dotnet .\FileRelocation.dll -v -e C:\Users\freerey\Desktop\firelloc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (No executable f...Relocation.dll":String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Since initially running into this issue, I have tried writing dotnet ef
in the front, only to be told Microsoft.EntityFrameworkCore.Tools.CommandException: No project was found. I have tried running the .csproj
file for my program instead of the .dll, but this results in the same outcome.
I feel like I'm missing out on something very obvious here, but due to my lack of experience with PowerShell and the fact that nobody I work with uses it, I still haven't found out why the program fails to run from a script when manually entering this data in works perfectly. The program works completely as intended and I know there isn't any issue with it; I just need to figure out how to get these scripts to stop having errors.
And for anyone curious: I'm running .NET Core 2.1.507, with these runtimes installed:
Thanks in advance!
Upvotes: 0
Views: 660
Reputation: 149
You gotta remember that when PowerShell is running it is running at the user level until told otherwise. There are two different permissions one as if you were running as an administrator.
C:\Windows\system32
and one that's user-level
C:\Users\UserName
In other words, you have to treat your PS1 script as if you opened it for the first time. There are many ways to resolve this issue but if you tell the script exactly where to run the file it will work.
So the PowerShell I script to test my DotNet 2.1 console app that says hello ends up being (demo.ps1)
dotnet "C:\Users\Neil\Source\Repos\DemoForStackOverFlow\DemoForStackOverFlow\bin\Debug\netcoreapp2.1\DemoForStackOverFlow.dll"
Now remember that your application could be more complicated than this and you could pass parameters into it, but that's likely out of scope for this context.
If you need more help attach the ps1 script to this post and we can go from there
Upvotes: 1