How to get file path of the file contained in dll file - c#

I have library "library.dll" where is something like that in the code:
PathModifier.AddEnvironmentPath("lib\\dlls", PathModifyMode.RelativeToProjectDirectory);
In this "dlls" folder are *.dll files (cca 20 files) which need to be added to Environment path. Properties of these files are set up like this:
Copy to Output Directiory: Do not copy and
Build Action: Resource
Library has about 30 MB, so dll files are contained in.
When I use this library in WPF project, there is problem, because
it try to find "lib\dlls" in WPF project directory instead of inside the "library.dll".
Is there any solution, how to say "find dlls folder only inside library, not in project, where is library used"?
Thanks.

If you are trying to centrilize the dependencies, then you should take a look at my answer here Nuget common folder. The idea is the same as saving all Nuget packages, all your dependencies should point to the same place, on this case the Common folder. On the Nuget scenario, you need to add an extra configuration to restore all packages from there and seed the nuget repository from that location.
In your case I think that the WPF project is looking inside the bin folder, and because you have the resources as Do not copy, then you can't find them inside, if you change that Copy Always will bring those dependencies inside your bin folder.

Related

nuget pack produces unwanted content folder out of nowhere

I have a .NET Framework class library project that I'm turning into a nuget package and uploading to my own nuget server.
This is how the project looks:
Really simple, just a single .cs file with a few classes.
I'm compiling the code with Debug configuration and Any CPU platform.
Produced files are the following: Synteco.ScriptInterpreter.dll and a .pdb file with the same name
In the directory of my .csproj file I also have a .nuspec file, which looks like this:
I'm only copying the Synteco-Icon.png file in the images folder in the final .nupkg in order to set the icon for my nuget package.
Upon running nuget pack I'm getting the following output
As we can see, everything seems to be in order.
However, if we look into the produced .nupkg file, its contents are:
Somehow the folder content has been created. In the past this folder was not created at all.
I am able to push this nuget package to my server, but when I download it via Nuget Package Manager in other projects, everything from the content folder is being copied into the project that is trying to use that nuget package. For larger packages this becomes a real issue and unwanted files are being copied to projects.
What is the issue and how can I stop the content folder from being created?
I've tried running nuget pack [NAME_OF_MY_NUSPEC_FILE] but that would produce something even more strange. Take a look:
Am I doing something wrong?
P.S.
As far as I'm concerned, this is how a proper nuget package should look like. This is Newtonsoft.Json:
Problem was solved!
Silly me, I actually had some files with build action set to Content in my C# project for my nuget packages!
Upon removing all items with that build action the content folder is gone!

C# Project what to put in Source control (Bitbucket)

I have created a C# project. I have created a Bitbucket account and want to put my project there.
What all should I put in the repository and what not to.
I am guess Debug and Release folders should not be uploaded. What about..
- Name/bin/Debug
- Name/obj/Debug
Thanks
It's a good idea to start with an established .gitignore file. GitHub has a project that maintains .gitignore files for various environments, including Visual Studio.
https://github.com/github/gitignore
Scroll down and grab VisualStudio.gitignore. Or you can download the file with this PowerShell command (set the current directory to the root of the repo, first):
(Invoke-WebRequest 'https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore').Content > .gitignore
This should give you an idea of what the general consensus is on what belongs in source control and what doesn't in a Visual Studio solution. In particular, this will exclude the bin and obj folders so you don't commit outputs to the repository, as well as the .vs folder and *.user files, which are user-specific data. It also excludes files and folders used by popular third-party extensions that maintain their own user-specific data.
Once you have a good .gitignore file, you can use git add --all and it will add everything that's not ignored to the index.
Nothing in bin or obj should need to be committed. You'll also need csproj files and nuget package config files (be they xml or json). Things like appconfig files, and .vscode are up to you whether you want to have them in source control.

Download the project from a repository without losing any project files. Sourcetree

When I upload a project from the local machine to the server repository, and try to download it from the server to another machine I am always missing some .dll files and cannot build the project?
It sounds like you're likely keeping externally needed DLLs in your bin folder, which would not be added to (many) source controls by default, as the DLLs in your bin folder get updated after each build.
The not adding bin to source is the correct route, you have a few options on what what you would need to do:
Use nuget packages that get restored automatically during build
add the DLLS to a separate folder (I like to use "extLib" or "3rdParty" as my folder name, and add that to source, referencing the DLLs in the separate folder.
ensure all machines have required DLLs/SDKs installed on the machine
They are listed in (my) order of preference, but that's just my own opinion.
Probably because repo's ignore file is ignoring those file types. Check you .gitignore file in the root of the repo.

How to export class libraries in Visual Studio 2012

In Eclipse when I implement a class library and I'm ready to deploy, I usually export and package it into a JAR file that later you can just add to the build path in another project. Is there an equivalent feature in Visual Studio? Is there a proper way to "publish" a class library and package it into a dll file to later add as a reference in another project? Or do you just usually go and dig for it in the bin folder yourself?
Most VS projects compile into a DLL. If you want your DLL to be "published" to some particular location when you build, you can use build events which can also package up your dll (you could call a batch script, for example, that takes care of that for you).
Is there a proper way to "publish" a class library and package it into a dll file to later add as a reference in another project? Or do you just usually go and dig for it in the bin folder yourself?
Sure, just add the bin\debug\yourdll.dll or bin\release\yourdll.dll as a reference in your other project, or otherwise to the location you moved it to in your build event. No need to go digging for it every time.
Change the output type to 'release' or 'Debug'.
Go to Build, Build Solution (Or f5)
Navigate to: The Solution Bin folder for release or debug.
3a. You can quickly navigate to the solution folder by right clicking the solution in the
'Solution explorer' and selecting 'Open folder in File Explorer'.
The compiled DLL file will be in that directory. (bin\release or bin\debug)

Getting Content Files and Primary Output programmatically

For some reason, we have a script that creates batch files to XCOPY our compiled assemblies, config files, and various other files to a network share for our beta testers. We do have an installer, but some don't have the permissions required to run the installer, or they're running over Citrix.
If you vomited all over your desk at the mentions of XCOPY and Citrix, use it as an excuse to go home early. You're welcome.
The code currently has hundreds of lines like:
CreateScripts(basePath, "Client", outputDir, FileType.EXE | FileType.DLL | FileType.XML | FileType.CONFIG);
It used to be worse, with 20 int parameters (one per file type) representing whether or not to copy that file type to the output directory.
These hundreds of lines create upload/download batch files with thousands of XCOPY lines. In our setup projects, we can reference things like "Primary output from Client" and "Content Files from Client". I'd love to be able to do that programmatically from a non-setup project, but I'm at a loss.
Obviously MS does it, either using an API or by parsing the .csproj files. How would I go about doing this? I'm just looking for a way to get a list of files for any of the setup categories, i.e.:
Primary Output
Localized Resources
Content Files
Documentation Files
EDIT:
I have a setup project like Hath suggested, and it's halfway to what I'm looking for. The only problem keeping that from being a perfect solution is that multiple projects depend on the same assemblies being in their own folder, and the setup will only copy the file once.
Example:
Projects Admin, Client, and Server all rely on ExceptionHandler.dll, and Admin and Client both rely on Util.dll, while Server does not. This is what I'm looking for:
Admin
Admin.exe
Admin.exe.config
ExceptionHandler.dll
Util.dll
Client
Client.exe
Client.exe.config
ExceptionHandler.dll
Util.dll
Server
Server.exe
Server.exe.config
ExceptionHandler.dll
Since the referenced assemblies are all the same, what I get is this:
Admin
Admin.exe
Admin.exe.config
ExceptionHandler.dll
Util.dll
Client
Client.exe
Client.exe.config
Server
Server.exe
Server.exe.config
This causes a FileNotFoundException when either Client or Server can't find one of the two DLLs it's expecting.
Is there a setup property I'm missing to make it always copy the output, even if it's duplicated elsewhere in another project's output?
EDIT AGAIN: All referenced DLLs are set to "Copy Local", and always have been. I found a decent article on using NAnt and XSLT to grab the list of files, so that may be a possible solution as well, as neouser99 suggested.
ACCEPTED SOLUTION: I'm pretty much back where I started. All .exe and .dll outputs are put into a "bin" directory in the setup project, loosely packed. The other per-application folders contain shortcuts to the executable in that directory.
The difference now is, I'm going to add a custom action to the installer to use reflection, enumerate the dependencies for each executable output, and copy the .exe and .dll files to the separate directories. Bit of a pain, as I just assumed there was a way to programmatically detect what files would be included via some setup library.
why not use another setup project and just set the 'Package files' setting to As Loose uncompressed files (setup project->properties)? then share the folder.. or something.
edit:
I see, you have 3 folders for your outputs. but the setup project only detects the ExceptionHandler.dll and Util.dll once, so it will just pick the first folder and put it in there.
You could do a setup project for each project - bit annoying maybe..
You could manually add in the dll's to the projects that are missing the assembly's
either by adding in the File by 'add file' or 'add assembly' or 'add project output' if you have those projects in the same solution.. (I doubt that's the case though).
or just dump all of them into one output directory...
Although it's designed as a build tool, you might find NAnt to be extremely useful in what you are talking about. The tasks (build, copy, move, delete, etc.) that you can define allow for very fine-grained file lookups, up to general, full folders. If you also incorporate NAnt into your build process, I think you could find that it helps out in more ways then one.
Another approach that has worked for me in the past is to add the shared resource (Assembly, DLL or project) as a reference to each of the Admin, Server and Client projects. Then open the properties panel for the referenced item in each project and set "Copy Local" to true.
Now when you build the projects, each will have its own instance of the Assembly copied into its output folder.
This should also cause the shared components added in this manner to be replicated in each of the output folders in the setup package.
A completely different approach could be to set them up as symbolic links on the network share. A symbolic link is basically a short-cut where the file-system hides the fact that it is a short-cut, so all other applications actually believes that the file has been copied (http://en.wikipedia.org/wiki/NTFS_symbolic_link).
One advantage of this approach is that the file is updated immediately as the file changes and not only when you build your projects. So when you for instance save one of the config-files with a text-editor the update is applied immediately.
The following MSBuild script part can build your SLN file (you can replace it with .csproj) and will report a list of all projects that were build (Dlls, EXEs).
<MSBuild Projects="MySolution.sln" Targets="Clean; Rebuild" Properties="Configuration=$(BuildMode);">
<Output TaskParameter="TargetOutputs"
ItemName="AssembliesBuilt" />
</MSBuild>
Now, this doesn't really solve your problem, but it gets you a list of everything that was build. You also have copylocal, so you could probably just take AssembiesBuild and copy all DLL and .CONFIG files from there.
Example:
AssembliesBuild = c:\myproj\something1\build.dll
you'd go to c:\myproj\something1\ and simply search for all *.dll and *.config files and include them. You can do this pretty easily with MSBuild or powershell, if you have it installed. To output a XCOPY script from MSBuild, I think you'll need MSBuild contrib projct installed.

Categories