My web project in Visual Studio 2010 has post-build events that copies files from a folder into the bin directory of the web project. But when I publish my site, MSBuild seems to ignore the post-build events and these files are NOT copied.
The solution is to create a BAT file that executes from a MSBuild Target. I called my BAT file PostBuildEventPublish.bat and it lives in my solution folder. This is the BAT file contents:
xcopy "%1References\UmbracoCourier.lic" "%2" /y
xcopy "%1References\jumps.umbraco.usync.dll" "%2" /y
The parameters %1 and %2 are input from the MSBuild csproj file. In VS2010 unload your web project and edit the project then insert this Target (at the bottom):
<Target Name="AfterPublish" AfterTargets="CopyAllFilesToSingleFolderForPackage">
<Exec Command="$(SolutionDir)References\PostBuildEventPublish.bat "$(SolutionDir)" "$(ProjectDir)obj\$(Configuration)\Package\PackageTmp\bin"" />
<Message Importance="Normal" Text="Finished PostBuildEventPublish.bat" />
</Target>
Obviously change to the paths you want to use.
As you can see parameter %1 = $(SolutionDir)
and parameter %2 = $(ProjectDir)obj\$(Configuration)\Package\PackageTmp\bin
You will notice that my Target always gets executed before the actual publish files are copied.
C:\Dev\Puma\Main\References\PostBuildEventPublish.bat "C:\Dev\Main\" "C:\Dev\Puma\Main\Web\obj\Debug\Package\PackageTmp\bin"
C:\Dev\Puma\Main\References\UmbracoCourier.lic
1 File(s) copied
C:\Dev\Puma\Main\References\jumps.umbraco.usync.dll
1 File(s) copied
Finished PostBuildEventPublish.bat
Publish Pipeline Deploy phase Pre-Deploy CopyAllFilesToOneFolder Stage
Deleting existing files...
Publishing folder /...
Publishing folder App_Browsers...
Publishing folder App_Data...
Publishing folder App_Data/packages...
Publishing folder App_Data/packages/created...
Publishing folder App_Data/packages/installed...
...
Publishing folder uSync/Template/ZMag...
Publishing folder Views...
========== Build: 5 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
So parameter %2 is where the magic happens. Here we copy the files into the temp publish folder and when Publish completes copying the files to the actual Publish folder these post-build files will also be copied.
Showing posts with label build. Show all posts
Showing posts with label build. Show all posts
Friday, 14 March 2014
Friday, 26 July 2013
StyleCop and R# Integration
StyleCop and R# Integration
You can either write
your own rule library or use an existing extension like StyleCop+.
I’ve used StyleCop+ as it holds common rules and is an open source community project
so adding to it is easy. I’ve investigate the StyleCop+ rule SP2101
MethodMustNotContainMoreLinesThan below.
Versions
Visual Studio 2010
R# 5.1.3000.12 and 8.0.14.856
StyleCop 4.7.44.0 and 4.7.45.0
StyleCop+ 1.8
R# 8 and StyleCop with StyleCop+
R#8 will NOT work with StyleCop 4.7.44.0 only 4.7.45.0. If you want to use StyleCop+ 1.8 on top of this you need to change the assembly binding redirects in the Visual Studio 2010 config file (C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config).
Make sure VS is closed and the StyleCopPlus.dll in C:\Program Files (x86)\StyleCop 4.7 has been deleted.
Under this XML...
Add this XML...
Place the StyleCopPlus.dll back in C:\Program Files (x86)\StyleCop 4.7 and Unblock it. Now open VS and everything should work!
R# 8 and StyleCop with StyleCop+
R#8 will NOT work with StyleCop 4.7.44.0 only 4.7.45.0. If you want to use StyleCop+ 1.8 on top of this you need to change the assembly binding redirects in the Visual Studio 2010 config file (C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config).
Make sure VS is closed and the StyleCopPlus.dll in C:\Program Files (x86)\StyleCop 4.7 has been deleted.
Under this XML...
<runtime>
<UseSmallInternalThreadStacks enabled="true"/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="StyleCop" publicKeyToken="f904653c63bc2738" />
<bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.7.45.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="StyleCop.CSharp" publicKeyToken="f904653c63bc2738" />
<bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.7.45.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="StyleCop.CSharp.Rules" publicKeyToken="f904653c63bc2738" />
<bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.7.45.0" />
</dependentAssembly>
Place the StyleCopPlus.dll back in C:\Program Files (x86)\StyleCop 4.7 and Unblock it. Now open VS and everything should work!
R# Integration
With these versions installed you can edit the StyleCop+
rule SP2101 to reduce the lines from 120 to 20 to test its working. Open Settings.StyleCop
file (Located in folder of project(s) or solution) then go
to the StyleCop+ tab and select the rules to edit.
Open the R# options dialog and go to Code Inspection > Inspection Severity
and find the StyleCop+ rule to show as an error.
An you’re done!
Build Integration
You can use the MSBuild targets file (e.g. C:\Program
Files (x86)\MSBuild\StyleCop\v4.7\StyleCop.Targets) provided with
StyleCop to fail the build in Visual Studio for any
of the projects you set this up for. The problem with this is all
violations are set to error and you can’t target individual rules to break the
build.
The solution I think is to use TeamCity to read the XML
violations file (e.g. \obj\Debug\StyleCopViolations.xml)
generated after the build and then fail the CI build if it finds an individual
rule violation. For example if you find this in the file:
<Violation LineNumber="19" Source="C:\DevelopmentSVN\ATMS\Trunk\Isotrak.Zinc\Isotrak.Zinc.ATMS\Common\MapModelHelper.cs" RuleNamespace="StyleCopPlus.StyleCopPlusRules" Rule="MethodMustNotContainMoreLinesThan" RuleId="SP2101">Method body must not contain more than 20 code
lines (now 25).</Violation>
Friday, 8 July 2011
Visual Studio Project is complied even though I've set it not to complie
I have a solution in Visual Studio 2010 with numerous projects and 1 of these projects must not be compiled when building the solution. I know you can set this in the Configuration Manager by un-ticking the Build checkbox.

But, there is another place as well that I over looked when working with a website project.
Right click on the website project
Select Property Pages > Build
Un-tick the Build solution action option Build Web site as part of solution

Simple enough but easily over looked.
Thursday, 9 June 2011
Could not load file or assembly 'XXXXX' or one of its dependencies. An attempt was made to load a program with an incorrect format.
This started happening all of a sudden when I tried to build or rebuild my VS2010 solution. This was because some of the projects in the solution target different platforms (mixed platforms).
I fixed this by going to the Configuration Manager... which is in the drop-down of your configurations (Debug, Release etc.) in VS2010. Then I set "Active solution platform" drop-down to "Any CPU".
I rebuilt the solution and it succeed in compiling.
I fixed this by going to the Configuration Manager... which is in the drop-down of your configurations (Debug, Release etc.) in VS2010. Then I set "Active solution platform" drop-down to "Any CPU".
I rebuilt the solution and it succeed in compiling.
Labels:
any cpu,
build,
configuration manager,
incorrect format,
platform,
target,
vs2010
Subscribe to:
Comments (Atom)

