My .NET project depends on a bunch of native dll libraries that should be copied into the same directory as .exe file. Dll files are added to main project to "ExternalDependencies" folder and are copied to output folder upon custom post-build action.
When I publish my app with ClickOnce utility all dlls are placed into ExternalDependencies/ relative path, not in the same directory as exe.
I don't want to put the libraries into root of the project, but I have to find a way to change relative path during installation.
I found no way of doing this, except for manual manifest generation: https://msdn.microsoft.com/en-us/library/xc3tc5xx.aspx
Maybe I am missing something? Is there an easier way to do this?
Ok, figured it out. This blog post describes the hidden possibilities of project files which allow to do what I want: http://blogs.msdn.com/b/mwade/archive/2008/06/29/how-to-publish-files-which-are-not-in-the-project.aspx
Basically you should add an item to you project file for each file you will be deploying if you want a custom path for it:
<ItemGroup>
<PublishFile Include="ExternalDependencies\DSAPI.dll">
<Visible>False</Visible>
<Group>
</Group>
<TargetPath>DSAPI.dll</TargetPath>
<PublishState>Include</PublishState>
<IncludeHash>True</IncludeHash>
<FileType>File</FileType>
</PublishFile>
TargetPath property is what I was looking for. It's a shame you cannot change it from VS UI!
Related
When I build a windows application. It does not work because it cannot read my app.config file. I looked in the bin directory and it does not have the appname.exe.config file. If I manually copy over the app.config and rename it the appname.exe.config the application will work..but when I build the project this file is never created automagically. What am I missing? Why is my project not creating it? I have looked through the whole folder structure and there is no other config files.
Everyone here is giving you false information I think. I think #bowlturner had it right. According to Microsoft, you do need to set the app.config's Copy to output directory property to either Copy Always or Copy if newer. From Microsoft's MSDN Site:
When you develop in Visual Studio, place the source configuration file for your app in the project directory and set its Copy To Output Directory property to Copy always or Copy if newer. The name of the configuration file is the name of the app with a .config extension. For example, an app called myApp.exe should have a source configuration file called myApp.exe.config.
Visual Studio automatically copies the source configuration file to the directory where the compiled assembly is placed to create the output configuration file, which is deployed with the app.
The correct settings are:
Build Action = None
Copy to Output Directory = Do not copy
and very important, the project file needs to contain this element:
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
The only thing that worked for me was to delete bin\ and obj\ entirely. Rebuild and the file is created fine.
Look on App.config properties, should be:
BuildAction: None
CopyToOutputDirectory: Do not copy
Custom tool and custom tool namespace should be empty
Also try to Rebuild project. Right click on project -> Rebuild
Assuming you're using Visual Studio click your config file in the Solution Explorer and and in the Properties panel set Copy To Output Directory to something other than Do Not Copy.
I'm new in Visual Studio 2013 (C#). I know in general it should be avoid putting bin directory in source control. However, in my bin directory, there are lots of dll files. Without this dlls, I can't build my project.
I thought maybe I should create a directory, such as 'lib' to store the dlls. But the fact is NuGet always put dll into the bin directory. Should I manually move the dll from bin to lib?
All I want is to simply put all source codes, resource files and dll files to source control (git). Then my team-mates can pull the project then build it in their machine.
edit on 1/4/2015: provide further details
For example, I installed log4net thru NuGet. After finished, I found 3 new files existed in bin directory:
log4net.dll
log4net.xml
log4net.dll.refresh
I tried to remove bin directory from my project, then rebuild my project, and hope to see that a new bin directory would be built and all dll/pdb/etc files would come back. But unfortunately it didn't happen.
In my understanding, the ideal process would be:
add reference/install package, then certain config info would be recorded and according files would be installed to bin directory;
when build, according lib files would be referenced from bin, if such files not found, VS would get the reference info from some place other than bin and download them again. So that's one of the reasons why we don't need to put bin into source control.
However, I found that's not true in my project.
Actually according to the official .gitignore, I found bin directory as build results is filtered ([Bb]in/). That is to say, even VS knows such directory should be ignored.
Maybe some wrong setting within my project?
I'd like to add files to a web csproj that are located under its directory, but in a different directory structure than the physical one. Example physical directory structure:
MyProject.csproj
Assets
Settings.config
Now my project needs the following structure when I publish the project (i.e. on the server when deployed) and would be nice if this structure would be visible from Visual Studio too:
MyProject.csproj
Config
Settings.config
Notice that Settings.config isn't in the Assets but in the Config folder.
I don't want to copy the files over, I can't move them and I can't change where these files are loaded from.
Is it possible for such files to be located in the Assets folder while
from VS they appear to be in the Config folder,
and when the project is published they are copied to the Config folder.
The latter one is possible with post-build tasks I think and I believe I can implement it. However I'd like to have the whole development experience, including the folder structure in VS, to show the file being under Config. Is this possible?
I'm looking for something like solution folders, but for projects. Adding files as links would work great, but since the files are in the physical folder of the project I get the error "Cannot add a link to a file that is inside the project tree".
I used the method suggested in the following post to include an App.config file to Class Library project.
Equivalent to 'app.config' for a library (DLL)
It works as mentioned and creates the .dll.config file in respective Class Library projects output directory (e.g. ApiCommunicator\bin\Debug).
I have referenced this Class Library project as a "Project Reference" from another Console Application project within the same Visual Studio solution.
Now the problem is, the .dll is getting copied to the Console Projects output directory (i.e. Engine\bin\Debug) but the .dll.config doesn't. If I manually copy it, everything works fine but is there a way to configure Visual Studio to auto copy .dll.config to any other project's output directory which references the Class Library project?
Thanks,
Bathiya
Although I am late, but my answer can help others. I used the following command as pre-build event:
copy /Y $(SolutionDir)\[YOUR_LIBRARY_PROJECT]\app.config $(ProjectDir)$(OutputPath)[YOUR_LIBRARY_NAME].dll.config
I tried to be dynamic as much as possible, and the above command worked.
I posted the same answer at the question Can we autocopy the *.dll.config? as well.
It would have to be the other way around: Projects referencing your dll could copy it's dll.config from a known location as a post-build event.
However I think it would be much better to provide the configuration from within the consumer application's configuration. That way each referencing project would have an option to adjust the configuration to its needs, which I would think is a critical feature.
If that is not the case, then I don't see the reason for having the .dll.config, and you can just hardcode the values.
You can use the 'Build Events' tab of your project properties to run command line instructions post-build or even pre-build. This way, you can use a simple
copy /Y "<yourconfigfilepath>" "<yourprojectfilepath>\Engine\bin\Debug\"
This will copy the dll.config file you are needing over to the correct directory.
I have an application that is published through the ClickOne mecanism. The issue I'm having is that it is not publishing my NLog.config file, which is required for my application to run. I've looked through the Application Files screen, but I don't see NLog.config as an option to select. My NLog.config file has a built action of Content and is set to copy to the output directory. If it matters the NLog.config file is in another project that is referenced in the project I'm publishing.
I'm aware that I can use MAGE to essentially scan my publishdirectory and have it update my manifest, but what I'm looking for is a way to do it automatically.
What are my options?
Possible Solution
One solution could be to configure NLog through code rather than XML.
I use this great tool too and I have a click-once program too:
In the Solution explorer, click on your nlog.config. In the properties window, put the Build Action as content.
Be sure that you see "Applications files" of the project's properties window.
VoilĂ !