Why is this Visual Studio post-build event not firing? - visual-studio-2010

I am trying to copy all of my output files from the solution target directory to a shared bin folder but for some reason the files are not being copied. For some reason, what seems like a very simple post-build command is not working for me.
xcopy "$(TargetDir).*" "$(SolutionDir)..\..\..\bin" /Y/I
Here's my directory tree:
- Development
- bin
- Clients
- Interface
- Services
- bin
- Debug
- Release
- Host
- bin
I need to copy the output from the Services -> bin -> Debug or Release folders to the Development -> bin folder following any successful build. I have tried various combinations of "..\" and none seem to work.

When I need to trouble shoot post build events
I add an ECHO ON, and generally do a DIR so I can see what directory I am in.

These suggestions did not help me. I'm using Microsoft Visual Studio Professional 2017 (VisualStudio/15.0.0-RTW+2622.4).
No matter what commands I put into the Post-Build Event, they were ignored. When I closed the Visual Studio session, I was prompted to save my solution file, and accepted this action.
When I opened Visual Studio again, my Post-Build Event commands were gone. When I re-entered the commands they worked.

In my case, just because someone accidently set the PostBuildEventUseInBuild node as "false".
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<PostBuildEventUseInBuild>false</PostBuildEventUseInBuild>
</PropertyGroup>

In my case i need to run "npm build" instead of "ng build"

Related

Explanation on specific differences between my click once publish when done via command line and from Visual Studio

I am trying to understand why is my WindowsForm app publish behaving differently, when done via command line and via Visual Studio's Publish.
The differences are:
In my command line publish, a copy of the .exe is placed in the top-directory publish folder, while it is not there, when published via VS
In my command line publish, the .application file is missing in the [Application Files] folder, while it is there when published via VS
A screen shot illustrating the exposed above:
Anyone has any idea why does this happen ? I have tried playing with the publish settings, but still without success.
Below is what my command line statement looks like (ran via Jenkins):
Explanation on specific differences between my click once publish when done via command line and from Visual Studio
That because some features are done by Visual-Studio and not by the MSBuild command line. So the click-once-deployment behaves differently when it's executed from the command-line.
When you publish via command line, only Project.exe and Setup.exe are copied to the deployment folder. You can switch the deployment folder by property PublishDir:
msbuild "ProjectName.csproj" /target:publish /p:Configuration=Release;PublishDir=D:\TestPublishFolder
When you publish from Visual Studio, Visual Studio will do some more features, including Application Files folder and .application file into deployment folder.
If you want to have the same publish result as Visual Studio when you publish via command line, you can custom target to achieve it.
See ApplicationFiles folder missing when ClickOnce publish with command line for more detailed info.
Hope this helps.

TFS 2015 Visual Studio Build - Package .zip not being created

I'm trying to build my solution and package up the web app into a web deploy (.zip) package to be deployed.
I've added the Visual Studio Build step with the following MSBuild Arguments:
/p:DeployOnBuild=True /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\"
And I've set up the Copy and Publish Build Artifacts step to copy all .zip files to the drop folder.
The build completes successfully but nothing is copied to the drop folder because there are no .zip packages that get created.
So when I look on the TFS server, the only thing in the 'a' folder is an empty 'drop' folder. And in the 's' folder is the solution directory with a PrecompiledWeb folder in it. Not sure what that is but it doesn't look like the deployment package (and it's not a .zip).
Any ideas?
I have tried the same on VS2015 MVC web application using VSTS and TFS 2015.2.1 both. I had to do a slight change to the Build arguments in Visual Studio build. That is removing the trailing "\" in /p:PackageLocation="$(build.artifactstagingdirectory)\".
Here is the argument I passed to Visual studio build step
/p:DeployOnBuild=True /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)"
Then I used Copy and Published Build Artifacts (Deprecated in VSTS you should use Copy task and Publish task instead of this task) as shown below
This gives me output as below.
First suggest you manually remote in the build agent and build the project through MSBuild command line with arguments to see if the project builds properly.
This will narrow down the issue is related to the environment on your build agent or your build definition.
You should directly use /p:PackageLocation=$(build.stagingDirectory
Besides since you have multiple assemblies that are referenced in the web app. Please also double check dependencies that are building in the correct order or referenced correctly.
Make sure the ASP.NET development workload of Visual Studio is installed.
If DeployOnBuild is having no effect, you may need to install the ASP.NET Development "workload" with the VS setup tool.
There are specific .targets files that, if they don't exist, cause these parameters to be silently ignored. Installing this adds those .targets and the parameters become active, allowing the .zip to be created.
For me (VS 2017) the relevant target file (or one of them, anyway) that was missing but is needed is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets
If it is missing, you'll need to install as above, and if it is there, then you have a different problem. ;)

What is the default location for MSBuild logs?

I am using Visual Studio Express 2012. Where is the location of the log file? I have searched in the folder where my solution and projects are stored, but cannot find any .log file.
This is the configuration for logging:
Log file from Visual Studio is only supported for C++ projects. You just have to work with the output window for others.
See this similar thread: VS2010: minimal build log in output and detailed log in log file
And in case you happen to do this for a C++ project, the file is at:
... build log in the intermediate files directory
... The path and name of the build log is represented by the MSBuild macro
expression, $(IntDir)\$(MSBuildProjectName).log.
Use build output instead of logging to file. Instead of copy/paste, simply click somewhere in the output and press CTRL + S to save. Visual Studio will prompt you for a location (tested with Visual Studio 2017, but I'm assuming this works in earlier versions too).
The msdn documentation is pretty clear about this (And you ain't gonna like it!):
https://msdn.microsoft.com/en-us/library/jj651643.aspx
Where it says:
To create a build log file for a managed-code project On the menu bar,
choose Build, Build Solution.
In the Output window, highlight the
information from the build, and then copy it to the Clipboard.
Open a
text editor, such as Notepad, paste the information into the file, and
then save it.
While it's true that VS doesn't allow this directly, it is still possible to build with MSBuild "inside" VS2015 and get both the build window output and the log file, as follows: (Arguably this is a bit of a hack.)
In your VS Managed solution, add a new project (Let's call it 'Make').
a. The project type you want is Visual C++/NMake project.
Define the MSBuild commands you need on the command line (see below).
Change the solution configuration to build the NMake project instead of the normal managed projects.
This will create a project that has Build, Rebuild, and Clean command lines where you can execute MSBuild directly. For example:
Rebuild: MSBuild.exe /ds /v:diag /property:Configuration=Debug ..\BuildTest\BuildTest.csproj /t:Clean,Build
Build: MSBuild.exe /ds /v:diag /property:Configuration=Debug ..\BuildTest\BuildTest.csproj /t:Build
Clean: MSBuild.exe /ds /v:diag /property:Configuration=Debug ..\BuildTest\BuildTest.csproj /t:Clean
You can also specify multiple MSBuild.EXE command lines in order to build multiple projects. For the usual build-the-entire-solution outcome you can target only the final end assemblies and let the dependency graph generate the individual targets.
This will produce a .log file, where NAME is the name of the NMake project you used. In the example above, the log would be make.log.
A working example is available on GitHub:
https://github.com/bitblitz/VS_MsbuildExample
(Tested with VS2015)
Note that building individual projects directly will still build with the normal VS behavior, but you can build the full solution inside VS and get the build logs.

Delete additional files when cleaning project

When executing build->clean solution in Visual Studio 2005 I want to also remove some debug text files that may exist in my build directory. The file name will always be the same, i.e. debug.txt. Is there a way to get Visual Studio to do this?
Go to Project->Properties and choose configuration properties.
THere's an entry "Extensions to delete on clean". Add *.txt to it and that just should do the trick. Or you can explicitly specify debug.txt

VS Post Build Event

I would like to implement a post build event that performs the following actions
A relative path copy of the DLL output (1 file, not all the debug jazz)
A register the output DLL to GAC
How is this done?
Does that do you want?
copy $(TargetPath) $(TargetDir)..\..\someFolder\myoutput.dll
regasm $(TargetPath)
(Entered into the field for post-build step under project properties)
Enter following into "Project properties->Build events->Post build events command line:"
xcopy "$(TargetPath)" "target path" /Y && regasm "$(TargetPath)"
or add following snippet to project (e.g. csproj) file
<PropertyGroup>
<PostBuildEvent>xcopy "$(TargetPath)" "target path" /Y && regasm "$(TargetPath)"</PostBuildEvent>
</PropertyGroup>
Note that it is recommended to add "" around copy command arguments to avoid problems with paths containing whitespaces. Also note that multiple commands can be combined using &&
Are you sure you want to do this as part of a compile? I would recommend using project references in solutions rather than the GAC if you can avoid it. Copying files is one thing, but registering in the GAC is fairly intrusive and you may want to consider the other environments your code is compiled in. Things like other developers' machines, and test environments/build servers etc. If you have a build server really you should be using something like NAnt with some sort of continuous integration server.
I had to same issue and I struggled a bit to make it works.
In my case, I wanted to do the other way around which is copying the SDL dll into my output folder.
copy "$(SolutionDir)SDL\lib\x86\SDL.dll" "$(SolutionDir)$(Configuration)\"
Note that, $(Configuration) will be your output folder (e.g. Debug or Release).
The quotes was what I was missing, apparently you need them when the right hand side end with a \. Thus, it might be safer to always use them.
Hope to save someone else a 5 minutes!
P.S. I use Visual Studio 2010
you may want to look at MS Build. Its what we use here at work.
CodeProject Link &
MSDN Ref
For step 2 in the question I seem to prefer the following:
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil" /f /i $(TargetPath)
Note: this requires the Windows SDK to be installed on your development machine.
More info on the available macros, such as $(TargetPath), on MSDN.
Ran into a related issue. The answers here helped (thanks!).
My scenario was in debugging an MEF-reliant application I needed to have the related DLLs in a particular location. I ran into issue with overwriting the prior build so did need to add a delete to the script.
delete $(SolutionDir)FileService\$(ProjectName).dll
copy $(TargetPath) $(SolutionDir)FileService\$(ProjectName).dll
Hope that helps someone, too!
This question is old. The easiest way is to add something like this on your .csproj file. For example I am running some tests on a virtual machine and its nice to have it sent to it after I compile:
<Project>
...
<!-- Upload to virtual machine -->
<Target Name="rsync" AfterTargets="Build">
<Exec Command="C:\Windows\System32\wsl.exe rsync -azv -e 'ssh -i /path/to/my/private/key' --delete /mnt/c/repos/MyProject/bin/Debug/net7.0/ root#vm.ublux.com:/usr/share/foo/" />
</Target>
</Project>

Resources