50 Replies
the only problem is the files I have are not opening when new user installs the app
I'm going to assume that your installer does not place the PDF files in
C:\Users\asus\source\repos\...
etc?I am creating installer by Microsft Visual Studio installer project
inside visual studio
but in this picture I have delated it
Do you understand what the problem is?
yes I do but I am having hard time to explain bro
You're trying to open the file
C:\Users\asus\source\repos\...
, but if your installer hasn't created that exact file (and I doubt it's creating new users), then obviously that file won't existyeah
how can I fix it
OK, so you understand that the problem isn't the installer? The problem is that your application hard-codes the PDF path, to a path on your (and only your) computer
Don't "bro" me please
oke sory
yeah problems with path
exactly
So, You want to tell your application to open the path relative to where your exe is, and not a fixed path
yess
So put your PDFs next to your exe (or in a folder next to your exe).
AppContext.BaseDirectory
is the folder which contains your exe. So use Path.Join(AppContext.BaseDirectory, "Files", "Test1.pdf")
etchow can I do that, I mean it is my first project and I am novice
Ai also said that to me
You can tell VS to copy the PDFs next to your exe. Add the PDFs to your visual studio project, then right-click, properties, and set "Copy to Output Directory" to "Copy if newer"
is there any videos if possible
related to this topic
I will learn and come back
Video about what?
How to right-click the file and change it's properties?
doing this in my project
xd
Kids these days... You need to learn by doing. Play with things. Click around, see what the options are.
okey let me try then
I will come back
Add the PDFs to your project as I described. Build your project, and see for yourself whether VS is putting them into the right place on build
Then start updating your application to construct paths relative to
AppContext.BaseDirectory
. Write some code, see what paths it constructs (have a look in the debugger), and if it's not right keep fixing it until it worksshould I rewrite each path, I mean I have about 40-50 PDFs and path for each of them( sorry if it went off topic)
What do you think?
If there's this many, you should probably consider enumerating all files in the directory, looping through that, and doing whatever you need to do with those files in a loop
I have 10 hour experience so far sorry If I sound stupid(
okey I will try
That's a very complex project to be making as your first dip into C#
You start with a "guess a number" in a console, not with something that has an installer
agree
but I have almost finished it
but I just want it share in Installer format
rather than bunch of files
$singlefile
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true
Use of -p:PublishSingleFile=true
implies --self-contained true
. Add --self-contained false
to publish as runtime-dependent.
-r RID
and -p:PublishSingleFile=true
can be moved to .csproj as the following properties:but to target multiple RIDs, you have to use dotnet publish
with the -r
option for each RID.
You can also add -p:IncludeNativeLibrariesForSelfExtract=true
to include native libraries (like Common Language Runtime dlls) in the output executable, but be aware of drawbacks and consider using an installer framework instead of that property with PublishSingleFile.
You might want to instead publish your application compiled Ahead Of Time to native code, see $nativeaot for examples.
Single file publishing | Runtime Identifier (RID) catalog | dotnet publish
There are other ways to get a single file besides an installer btw
that would be graet
as well
They don't tend to work particularly well for GUI apps though 😛
I am having troubles with publishing single file
everything I have learned from Youtube or AI is not working on my computer
You're trying to go too far too quickly. If you don't understand what you're doing, and you can't try to fix the problems you encounter on the way, that means you're over-stretching yourself
@Elyorbek Since you're just getting started, why not drop it and start with something simple ?
You're never going to learn by just copy-catting a video, or copy-pasting something an AI says
Right now only thing I need is to create singlefile
C:\Program Files\dotnet\sdk\8.0.400\Microsoft.Common.CurrentVersion.targets(3040,5): error MSB4216: Could not run the "
ResolveComReference" task because MSBuild could not create or connect to a task host with runtime "NET" and architectur
e "x86". Please ensure that (1) the requested runtime and/or architecture are available on the machine, and (2) that t
he required executable "C:\Program Files\dotnet\sdk\8.0.400\MSBuild.dll" exists and can be run. [C:\Users\asus\source\r
epos\new First\new First\new First.csproj]
C:\Program Files\dotnet\sdk\8.0.400\Microsoft.Common.CurrentVersion.targets(3060,7): error MSB4028: The "ResolveComRefe
rence" task's outputs could not be retrieved from the "ResolvedFiles" parameter. Object does not match target type. [C:
\Users\asus\source\repos\new First\new First\new First.csproj]
it says this when I use command console
Slow down
You need to fix your absolute paths first
aha
You need to fix those whatever route you take
(that should be obvious, hopefully?)
yeah
I think I did it bro))
watched some relativ pathing videos and your instructions started to make sense)))
changed all pathing to only files/filename format and copied files folder to exe file
☝️
and created Files folder in Microsofr Visual studio installer and add all files)
oh sorry
refleks
Cool. Did you add the PDF files to VS, and set the Copy to Output Directory?
Glad it's starting to make sense
can you check app for me?
Once you learn some more, you can avoid having to modify all of the PDF paths individually
yaeh
#code-review
can I send only exe file there?
No, noone is going to run a random exe
agree
When I Exit by Defoult VS frame it is not exiting app just hiding it, it is still running. Can I fix that or should I create my own new Frame for the app??
with Close function