Reputation: 10417
I have a C# project. After building it, there are 4 files to deploy:
these files and MyProj's refer dll are in the output directory, bin/Release
.
I want to customize output directory (deployment is following this directory hierarchy):
+bin/Release
|--MyProj.exe
|--MyProj.exe.config
|--MyProj.pdb
|--MyProj.XML
|--+lib
|--|--<MyProj's refer dll>
|--+plugin
|--|--<empty directory. before deployment, I'll copy into there manually>
|--+Help
|--|--<empty directory. before deployment, I'll copy into there manually>
(Of course, there is probingPath="lib"
in MyProj.exe.config
.)
Until now, I make directories manually. But I want to do this automatically. Is there any way to do this automatically, through Visual Studio?
And I want to deploy MyProj to ClickOnce. Can I deploy this directory hierarchy (with files that I copy manually, inside plugin/
and Help/
) to ClickOnce?
Upvotes: 1
Views: 775
Reputation: 11227
my suggestion is to create all the folders you need in your solution file (so they will be managed by Visual Studio) - and then set click on "Properties" of the files inside those folder, and set Build Action
to be Content
and Copy to Output Directory
as Copy if Newer
:
I use this trick all the time to make sure files and folders are created in BIN
folder where I can use them later on.
Another benefit of doing this is that you don't need to modify build steps in order to get these files processed by ClickOnce - just go to project properties -> Publish -> Application Files - and set Publish Status
to "Include" for the files you need. They will be deployed with your app.
Upvotes: 1
Reputation: 20935
You can automate this by calling the Copy
task in MSBuild. You do that by opening your .csproj
inside the Visual Studio IDE after rightclicking and selecting 'Unload'. Then right click again and Edit the .csproj
file, which will show the .csproj
file in text / XML format.
Then paste something like the following and change it to your specific requirements. Note the Target is AfterBuild
.
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<YourDestinationDirectory>..\SomeDestinationDirectory</YourDestinationDirectory>
<YourSourceDirectory>..\SomeSourceDirectory</YourSourceDirectory>
</PropertyGroup>
<Target Name="AfterBuild">
<CreateItem Include="$(YourSourceDirectory)\**\*.*">
<Output TaskParameter="Include" ItemName="YourFilesToCopy" />
</CreateItem>
<Copy SourceFiles="@(YourFilesToCopy)"
DestinationFiles="@(YourFilesToCopy->'$(YourDestinationDirectory)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
</Project>
You can easily test your MSBUILD
changes by opening up a Visual Studio Command Prompt, and running the MSBUILD.exe against your project file. Do it 1 by 1 so you can catch any errors immediately.
Upvotes: 1
Reputation: 2338
From Visual Studio, you can right click the project and go to properties. In the Project Properties click on the "Build" tab. Here can customize your Output location. Also under the "Build Events" tab you can shell out commands to perform prep or post build work.
Upvotes: 0