I've upgraded to a new windows 10 development machine.
Everything works great, except post-build events in msbuild/visual studio.
This is for any project, new or existing.
They all work fine on other people's windows 7 machines.
They work fine on the build server (jenkins).
They do not work for me at all, either in visual studio or with msbuild.
PRE-build events works fine.
It's like the postbuild event isn't even defined.
Unfortunately, our postbuild events are fundamental to the build process.
Starting with a basic console app and configuring the build events as:
<PropertyGroup>
<PreBuildEvent>echo before build</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>echo after build</PostBuildEvent>
</PropertyGroup>
The build output is literally:
1>------ Rebuild All started: Project: ConsoleApplication1, Configuration: Debug Any CPU ------
1> before build
1> ConsoleApplication1 -> C:\dev\postbuild\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Running msbuild with /v:diag I get this section:
PostBuildEvent = echo after build
PostBuildEventDependsOn =
PreBuildEvent = echo before build
PreBuildEventDependsOn =
When running prebuild:
Target "PreBuildEvent: (TargetId:22)" in file "C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets" from project "c:\dev\postbuild\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.csproj" (target "CoreBuild" depends on it):
Using "Exec" task from assembly "Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "Exec" (TaskId:19)
Task Parameter:WorkingDirectory=bin\Debug\ (TaskId:19)
Task Parameter:Command=echo before build (TaskId:19)
echo before build (TaskId:19)
before build (TaskId:19)
Done executing task "Exec". (TaskId:19)
Done building target "PreBuildEvent" in project "ConsoleApplication1.csproj".: (TargetId:22)
When running PostBuild:
Target "PostBuildEvent: (TargetId:77)" in file "C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets" from project "c:\dev\postbuild\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.csproj" (target "CoreBuild" depends on it):
Done building target "PostBuildEvent" in project "ConsoleApplication1.csproj".: (TargetId:77)
Related
Has anyone managed to build Xamarin Android apps with VS2017 MSBuild and Jenkins?
On our build machine we can build via the command prompt but when building via Jenkins we get this error.
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2371,2):
error MSB4062: The "Xamarin.Android.Tasks.GetAndroidPackageName" task
could not be loaded from the assembly C:\Program Files (x86)\Microsoft
Visual
Studio\2017\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll.
Method 'get_BuildEngine' in type 'Xamarin.Android.Tasks.AsyncTask'
from assembly 'Xamarin.Android.Build.Tasks, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' does not have an implementation.
Confirm that the declaration is correct, that the assembly
and all its dependencies are available, and that the task contains a
public class that implements Microsoft.Build.Framework.ITask
We're using a Pipeline script with the following command. The same command works fine with VS2015 MSBuild and Jenkins.
bat "${msbuild15} /consoleloggerparameters:ErrorsOnly /v:quiet
/p:Configuration=ProductionRelease /p:Platform=\"Any CPU\" /t:Rebuild
Field\Product.Android.sln"
GetAndroidPackageName
This task will be failed majorly because your manifest file gets malframed, may be that manifest xml malframed, unncessary charecters might be present.
Remove them And your issue will be solved..
I have added the following AfterBuild task to a .vcxproj file:
<Target Name="AfterBuild">
<Message Text="Hi" Importance="high" />
</Target>
It seems to run only if the the C++ code is built (or if I do a rebuild):
1>------ Rebuild All started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1> stdafx.cpp
1> SomeClass.cpp
1> ConsoleApplication1.vcxproj ->
1> Hi
D:\Projects\CppTest\Debug\ConsoleApplication1.lib
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
It doesn't run when the the C++ code is up-to-date:
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
How can I make it always run? I'm using Visual Studio 2015.
The line
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
means that Visual Studio didn't run MSBuild at all.
For incremental builds VS uses File Tracker to intercept file operations being performed by compiler and linker. Results can be fould in ProjName.tlog folder. In subsequent builds VS checks dates of files listed in .read and .write files and decides whether to run MSBuild. This feature is described in Hashimi S., Bartholomew S. - Using MSBuild, 2nd Edition - 2013, "File Tracker" chapter.
Some of possible solutions:
Use FileTracker API in your custom build tool.
Manually write file name(s) produced by your tool in some .write file (this solution is simple but is not guaranteed to work in future VS versions).
Build your solution by MSBuild instead VS.
Build your solution from bat-file, which calls devenv first then your tool.
I got around this issue by adding the following lines to my .vcxproj file:
<PropertyGroup>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>
It seems to force the IDE to actually run MSBuild.
I tested it in Visual Studio 2015. Adding the same lines to an imported .targets file did not help.
There is a setting "Run the post-build event:" in project properties in Visual Studio, and you need to set it to: "Always" for the post-build event to run always.
I guess it's now set to "On successful build".
Build your project with detailed logging (/v:detailed or /v:diag) and find the target which being run last but present in both cases (lets say it's a made up target "FinalCleanup"), then hook your post-build target like this rather than by the special name
<Target Name="RunMyLastTarget" AfterTargets="FinalCleanup">
<Message Text="Hi" Importance="high" />
</Target>
I finally went with Custom Build Step. To ensure that it always runs I set the Outputs field to some dummy file path. Since the dummy file path is never present, the Custom Build Step always runs. It is hacky, but it gets the job done.
I'm using Visual Studio 2010 and BizTalk 2010.
When I add a new Empty BizTalk Server Project and build it, I get the following output:
------ Build started: Project: ThrowAway1, Configuration: Debug Any CPU ------
ThrowAway1 -> c:\...\Projects\ThrowAway1\ThrowAway1\bin\Debug\ThrowAway1.dll
ThrowAway1 -> c:\...\Projects\ThrowAway1\ThrowAway1\bin\Debug\ThrowAway1.dll
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
I already tried deactivating the release build. But I still get two build events - which also affects the post build event.
With a default console application I get only one build event.
My goal is to run my own deployment PowerShell script in the post build event. The script is coming along nicely but it is called two times by this behavior.
This appears to be the expected behavior of a BizTalk Project.
I'm only speculating that it's because many BizTalk artifacts are compiled in a two step process. Orchestrations to C# then C# to the output Assembly for example.
The only thing I can recommend is to either make the script deterministic or maybe a side project that runs the post build for the entire Solution.
You can also investigate the BizTalk Deployment Framework: http://biztalkdeployment.codeplex.com/
As a pragmatic solution:
Checking the .btproj MSBuild file and its imports
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\BizTalk\BizTalkC.targets" />
where BizTalkC.targets imports
<Import Project="$(MSBuildExtensionsPath)\Microsoft\BizTalk\BizTalkCommon.targets" />
shows the usage of $(SecondBuild) in BizTalkCommon.targets.
This can be used in the post build event:
if "$(SecondBuild)"=="true" (
rem Run script.
)
For the first build $(SecondBuild) will be empty/undefined.
After some changes to my project, Visual Studio started to always re-compiles all sources, causing all dependent project to also re-compile, slowing down development considerably. Why is that?
Happens only when XML documentation file is checked and there's some file with Copy always. If you change either of these, the sources don't get re-compiled.
Happens only when compiling inside Visual Studio - when compiling using MSBuild from commandline, the sources don't get re-compiled.
Visual Studio 2012 Update 4.
This appears to be a bug in Visual Studio, when project has XML documentation file checked some files with Copy always.
Repro:
Create new project - C# class library.
Project Properties => Build => check XML documentation file
Project => Add => New Item => Text file TextFile1.txt
Change TextFile1.txt Copy to Output Directory to Copy always
Right-click project => build
project compiles
Right-click project => build
Expected: Project shouldn't be built, build output should say:
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
Actual: Project is build, output is:
------ Build started: Project: ClassLibrary1, Configuration: Debug Any CPU ------
ClassLibrary1 -> bin\Debug\ClassLibrary1.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Intestigation: Turning on detailed log, you see:
Target "CoreCompile" in file "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets" from project "ClassLibrary1.csproj" (target "Compile" depends on it):
Building target "CoreCompile" completely.
Output file "bin\Debug\ClassLibrary1.XML" does not exist.
Looking in procmon, you see that devenv.exe renames "ClassLibrary1.XML" into "vsA381.tmp" just before MSBuild.exe runs. Stack trace for the rename:
KERNEL32!MoveFileW+0x17
csproj!CMoveOutOfTheWayScope::EnterScope+0x85
csproj!CVsProjBuildableProjectCfg::StartBuildProcessWithTarget+0x50b
csproj!CVsProjBuildableProjectCfg::StartBuildProcess+0xc
csproj!CVsProjBuildableProjectCfg::StartBuildEx+0x15
msenv!CSUIBuilder::DoBuild+0x1a3
msenv!CSUIBuilder::Run+0x66
I'm updating some VS SharePoint projects so when they are built, both dll's and wsp's (packages) are created.
I found this page describing the process, but issue is that, while my project file looks like this:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\SharePointTools\Microsoft.VisualStudio.SharePoint.targets" />
<PropertyGroup>
<BuildDependsOn>$(BuildDependsOn);CreatePackage</BuildDependsOn>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>"$(SolutionDir)PostBuild.cmd" "$(SolutionDir)" "$(TargetDir)"</PostBuildEvent>
</PropertyGroup>
PostBuild.cmd is run BEFORE packaging happens, so when starting clean, this is the output:
------ Rebuild All started: Project: Sample, Configuration: Debug Any CPU ------
SampleProject -> C:\Inter\bin\Debug\Sample.dll
C:\Inter\bin\Debug\Sample.dll
1 File(s) copied
File not found - *.wsp
0 File(s) copied
Successfully created package at: C:\Inter\Sample\bin\Debug\Sample.wsp
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Any ideas? Thanks!!!
Solution can be found here.
Visual Studio & SharePoint: how to create package as part of the build
process In order to build a project and have the package created, this
can be added to the project file (csproj, vbproj):
<PostBuildEventDependsOn>
$(PostBuildEventDependsOn);
CreatePackage;
</PostBuildEventDependsOn>
That's right. PostBuild event occurs after buiding assembly.