I'm looking for a way to have an encrypted version of the app.config file in the ouput folder. Below I'll describe what I've done so far for accomplish this.
put those commands in the post-build event:
copy "$(ProjectDir)App.config" "$(ProjectDir)App_copy.config"
rename "$(ProjectDir)App.config" web.config
aspnet_regiis -pef connectionStrings "$(ProjectDir.TrimEnd('\\'))" -prov DataProtectionConfigurationProvider
rename "$(ProjectDir)web.config" App.config
This encrypt the file app.config properly. But it make the app.config no longer human redable. I'd like somehow to after the application compile and the app.config from $(ProjectDir) is in the output folder, run this command (to have the app.config file human readable again):
rename "$(ProjectDir)App_copy.config" app.config
How can I do that using VS build system?
Related
I have some custom made XML files and a read me file that I've included in my project.
How do I make it so that these files are copied to my debug/release folders automatically when I build my project? I've tried setting the Copy to Output Directory property to "Copy Always" but this doesn't seem to do the trick.
I'm using VS2010
I've found the answer. The build action needs to be set to Content if you want to just directly copy the file to the output folder.
Is there a way how to use web.config from my project that us under the test.
I have in mind something dynamically coping the file into my project?
You could use VS build events. Assuming you want to copy web.config from your webapp project to test project you can try something like this:
Select your Test project and open its properties window (Alt + Enter)
Navigate to Build events tab
Edit Pre-build event command line textbox to following line:
copy "$(SolutionDir)MyWebApp\web.config" "$(TargetDir)"
Command above will take web.config file from your MyWebApp project in solution directory and copy it to current project's (Test) target directory (which should be \bin).
Now, everytime you build your test project, web.config will be copied to its target directory.
I don't know what info from web.config you need in your test project. However, the need for a config file is usually a smell that you actually do integration testing rather than unit testing.
I'd like to copy a file and include the file in the web project and would like to do this as a part of the Pre/Post build events.
My understanding is that these events support DOS commands and I can use xcopy for copying a file, but I am not sure how I would update the csproj file to include the file in the project.
Do you need the file to be in the output directory or actually be part of the .csproj file ?
If you really want to update the csproj file then try customising the AfterBuild target in the csproj file of the startup project in your solution. All csproj files are msbuild files and you can use the full power or msbuild including callling any task. Right click on the project in the solution explorer, select unload project and then edit project. Then customise the AfterBuild target to change the particular csproj file you want. Use built in tasks or the excellent extension pack for changing the file. Finally reload the project.
I'm using log4net with a VisualStudio WinForms app, and I need log4net to find its config file. (I must keep the config settings in a separate file.)
It works if the config file is in the directory with the executable, but how do I get it there? For now I've added a post-build action:
copy "$(ProjectDir)test.log4net.xml" "$(TargetDir)"
But isn't there a better way? For such a simple task this seems like an awful kludge.
It's only a problem in development, because at deployment I can install the file with the executable. I'm using VS 2010, if that matters.
I "include" the configuration file so that it's visible in the Solution Explorer, and then in the file's properties in Visual Studio, set "Copy to Output Directory" = "Copy Always".
How can I make a project file (VS 2008) that just has some data files in and has no built output?
I can make an empty project and add my data files to it (which get copied to the output folder
), but it produces an EmptyProject.dll after I do a build. I want just my data files in the output directory and not some empty DLL or EXE.
I want the data files to be the only thing in this project as the project will be shared in a couple of solutions.
Our application is C#. All of our normal code projects are C#.
The data files are schemas (XSD). I want these schemas to be in the output folder, but I don't want them included with an existing project. I would like a project named "Schemas" that has nothing in except the XSD files and does nothing except copy the XSD files to the output folder. I would like this in a project file so that the same schemas project can be referenced in multiple solutions.
I don't know of a way to suppress the creation of the .dll file. BUT... here's an easy workaround. In the project properties, Build Events tab, write a Post-build event command line that will delete the file. Something like:
del path\filename.dll
Expanding on Scott's answer:
Create a new project of type Empty project
In Properties->Application, change Output type to Class Library
In Properties->Build->Advanced, change Debug Info to None
In Properties->Build Events, set the Post-build event command line to del $(TargetPath)
That way, the project creates only a DLL, which gets deleted. At the same time, the "copy to output directory" settings on your data files is respected.
Possibly another way is editing the csproj file by replacing this:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
with this:
<Target Name="Build" />
<Target Name="Rebuild" />
Then builds don't create anything. It worked for me.
Same general idea should work for any xxproj file. Just replace the <Import Project...> tags with the <Target...> tags.
I'd be interested in knowing if this causes any issues or doesn't work for anyone.
What do you need a project for if you're not building it?
You can use solution folders to "store" files...
Why not just disable building this project for all configurations (use the Configuration Manager) - that way it won't build.
Great stuff. Expanding on Scott > Daniel's answer:
Safe to remove all References and Properties (AssemblyInfo.cs)
If it is a node/grunt/gulp project then you can invoke it in your Build Events > *Post-build event command line * eg: gulp build or gulp clean
Perhaps you can add removal or obj and bin output folders to your node/grunt/gulp clean scripts mitigating the need for del $(TargetPath)