{"id":1170,"date":"2011-03-05T15:08:38","date_gmt":"2011-03-05T13:08:38","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1170"},"modified":"2011-03-05T15:11:19","modified_gmt":"2011-03-05T13:11:19","slug":"build-incrementer-add-in-for-visual-studio-latest-visual-studio-versions","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1170","title":{"rendered":"Build Incrementer Add-In for Visual Studio: Latest Visual Studio Versions"},"content":{"rendered":"<p>If you share concept (as I do) that every build should have a unique file version stamp in it, for a simple purpose \u00e2\u20ac\u201c at least \u00e2\u20ac\u201c to distinguish between different version of the same binary, then a helpful tool of automatic incrementing fourth number in FILEVERSION&#8217;s file version is something you cannot live without. After going through several fixes and updates, it is finally here available for download.<\/p>\n<p>The last issue was in particular that projects that are in solution&#8217;s folder are not found by the add-in with <a href=\"http:\/\/www.microsoft.com\/visualstudio\/en-us\/\">Visual Studio<\/a> 2008. Why? <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa301986.aspx\">OnBuildProjConfigBegin<\/a> event provides you with a unique project name string in Project argument, but it appears that it is only good enough as a quick lookup argument with Visual Studio 2010.<\/p>\n<pre style=\"color: #000000; background: #ffffff;\"><span style=\"color: #696969;\">\/\/ EnvDTE::_dispBuildEvents<\/span>\r\n    STDMETHOD<span style=\"color: #808030;\">(<\/span>OnBuildBegin<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">(<\/span>_EnvDTE_vsBuildScope Scope<span style=\"color: #808030;\">,<\/span> _EnvDTE_vsBuildAction Action<span style=\"color: #808030;\">)<\/span> <span style=\"color: #800000; font-weight: bold;\">throw<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span>\r\n    STDMETHOD<span style=\"color: #808030;\">(<\/span>OnBuildDone<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">(<\/span>_EnvDTE_vsBuildScope Scope<span style=\"color: #808030;\">,<\/span> _EnvDTE_vsBuildAction Action<span style=\"color: #808030;\">)<\/span> <span style=\"color: #800000; font-weight: bold;\">throw<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span>\r\n    STDMETHOD<span style=\"color: #808030;\">(<\/span>OnBuildProjConfigBegin<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">(<\/span>BSTR <strong><span style=\"text-decoration: underline;\">Project<\/span><\/strong><span style=\"color: #808030;\">,<\/span> BSTR ProjectConfig<span style=\"color: #808030;\">,<\/span> BSTR Platform<span style=\"color: #808030;\">,<\/span> BSTR SolutionConfig<span style=\"color: #808030;\">)<\/span> <span style=\"color: #800000; font-weight: bold;\">throw<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #800080;\">{<\/span>\r\n        _Z4<span style=\"color: #808030;\">(<\/span>atlTraceCOM<span style=\"color: #808030;\">,<\/span> <span style=\"color: #008c00;\">4<\/span><span style=\"color: #808030;\">,<\/span> _T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">Project <\/span><span style=\"color: #0f69ff;\">\\\"<\/span><span style=\"color: #0f69ff;\">%s<\/span><span style=\"color: #0f69ff;\">\\\"<\/span><span style=\"color: #0000e6;\">, ProjectConfig <\/span><span style=\"color: #0f69ff;\">\\\"<\/span><span style=\"color: #0f69ff;\">%s<\/span><span style=\"color: #0f69ff;\">\\\"<\/span><span style=\"color: #0000e6;\">, Platform <\/span><span style=\"color: #0f69ff;\">\\\"<\/span><span style=\"color: #0f69ff;\">%s<\/span><span style=\"color: #0f69ff;\">\\\"<\/span><span style=\"color: #0000e6;\">, SolutionConfig <\/span><span style=\"color: #0f69ff;\">\\\"<\/span><span style=\"color: #0f69ff;\">%s<\/span><span style=\"color: #0f69ff;\">\\\"<\/span><span style=\"color: #0f69ff;\">\\n<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #603000;\">CString<\/span><span style=\"color: #808030;\">(<\/span>Project<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #603000;\">CString<\/span><span style=\"color: #808030;\">(<\/span>ProjectConfig<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #603000;\">CString<\/span><span style=\"color: #808030;\">(<\/span>Platform<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #603000;\">CString<\/span><span style=\"color: #808030;\">(<\/span>SolutionConfig<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n        _ATLTRY\r\n        <span style=\"color: #800080;\">{<\/span>\r\n            <span style=\"color: #696969;\">\/\/ NOTE: const CString&amp; cast forces compiler to process statement as variable definition rather than function forward declaration<\/span>\r\n            CProjectConfiguration ProjectConfiguration<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #800000; font-weight: bold;\">const<\/span> <span style=\"color: #603000;\">CString<\/span><span style=\"color: #808030;\">&amp;<\/span><span style=\"color: #808030;\">)<\/span> <span style=\"color: #603000;\">CString<\/span><span style=\"color: #808030;\">(<\/span>Project<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #603000;\">CString<\/span><span style=\"color: #808030;\">(<\/span>ProjectConfig<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #603000;\">CString<\/span><span style=\"color: #808030;\">(<\/span>Platform<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #603000;\">CString<\/span><span style=\"color: #808030;\">(<\/span>SolutionConfig<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n            CRoCriticalSectionLock DataLock<span style=\"color: #808030;\">(<\/span>m_DataCriticalSection<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n            <span style=\"color: #696969;\">\/\/ NOTE: Check the project on the first run only (to skip multiple increments in batch build mode)<\/span>\r\n            <span style=\"color: #800000; font-weight: bold;\">if<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">!<\/span>Project <span style=\"color: #808030;\">|<\/span><span style=\"color: #808030;\">|<\/span> m_VersionMap<span style=\"color: #808030;\">.<\/span>Lookup<span style=\"color: #808030;\">(<\/span>ProjectConfiguration<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span>\r\n                <span style=\"color: #800000; font-weight: bold;\">return<\/span> S_FALSE<span style=\"color: #800080;\">;<\/span>\r\n            _Z3<span style=\"color: #808030;\">(<\/span>atlTraceGeneral<span style=\"color: #808030;\">,<\/span> <span style=\"color: #008c00;\">3<\/span><span style=\"color: #808030;\">,<\/span> _T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">Checking project <\/span><span style=\"color: #0f69ff;\">\\\"<\/span><span style=\"color: #0f69ff;\">%s<\/span><span style=\"color: #0f69ff;\">\\\"<\/span><span style=\"color: #0000e6;\">...<\/span><span style=\"color: #0f69ff;\">\\n<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #603000;\">CString<\/span><span style=\"color: #808030;\">(<\/span>Project<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n            <span style=\"color: #696969;\">\/\/ Checking the project is of C++ kind<\/span>\r\n            CComPtr<span style=\"color: #800080;\">&lt;<\/span>EnvDTE<span style=\"color: #800080;\">::<\/span>Project<span style=\"color: #800080;\">&gt;<\/span> pProject <span style=\"color: #808030;\">=<\/span> GetProject<span style=\"color: #808030;\">(<\/span>CComVariant<span style=\"color: #808030;\">(<\/span><strong><span style=\"text-decoration: underline;\">Project<\/span><\/strong><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n            _A<span style=\"color: #808030;\">(<\/span>pProject<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n            <span style=\"color: #808030;\">.<\/span><span style=\"color: #808030;\">.<\/span><span style=\"color: #808030;\">.<\/span><\/pre>\n<p>When the project is in a folder, <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa301425.aspx\">Projects::Item<\/a> can just fail if you are looking up for the element interface. In which case, you have to walk the collection taking into account <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa301157.aspx\">SubProjects<\/a> and additionally look there yourself. Visual Studio 2010 is one step smarter and gives the thing to you right from the start.<\/p>\n<p>Eventually, the add-in is here. It&#8217;s job is to go to .RC file and increment file version each time you build the binary. It reports the action into build output window:<\/p>\n<p><a href=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2011\/03\/Image001.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-1172 alignnone\" title=\"Build Incrementer Report in Visual Studio Build Output\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2011\/03\/Image001-800x213.png\" alt=\"\" width=\"640\" height=\"170\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2011\/03\/Image001-800x213.png 800w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2011\/03\/Image001-320x85.png 320w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2011\/03\/Image001.png 877w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>To install the add-in:<\/p>\n<ul>\n<li>download and register (regsvr32, administrator) the <a href=\"http:\/\/www.assembla.com\/code\/roatl-utilities\/subversion\/nodes\/trunk\/VisualStudioBuildIncrementerAddIn\/_Bin\/Release\/VisualStudioBuildIncrementerAddIn.dll?format=raw\">VisualStudioBuildIncrementerAddIn.dll<\/a><\/li>\n<li>apply one or more Visual Studio integration registry files:\n<ul>\n<li><a href=\"http:\/\/www.assembla.com\/code\/roatl-utilities\/subversion\/nodes\/trunk\/VisualStudioBuildIncrementerAddIn\/Visual Studio 2008 Registration.reg?format=raw\">Visual Studio 2008 Registration.reg<\/a><\/li>\n<li><a href=\"http:\/\/www.assembla.com\/code\/roatl-utilities\/subversion\/nodes\/trunk\/VisualStudioBuildIncrementerAddIn\/Visual Studio 2010 Registration.reg?format=raw\">Visual Studio 2010 Registration.reg<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Or, alternatively, use installation file <a href=\"http:\/\/www.assembla.com\/code\/roatl-utilities\/subversion\/nodes\/trunk\/VisualStudioBuildIncrementerAddIn\/_Bin\/Release\/VisualStudioBuildIncrementerAddInSetup.msi?format=raw\">VisualStudioBuildIncrementerAddInSetup.msi (version 1.0.4, 379K)<\/a> to have it done for you in a user-friendly way. Partial <a href=\"http:\/\/www.assembla.com\/code\/roatl-utilities\/subversion\/nodes\/trunk\/VisualStudioBuildIncrementerAddIn\">source code<\/a>, a Visual Studio 2010 projectis also there in repository.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you share concept (as I do) that every build should have a unique file version stamp in it, for a simple purpose \u00e2\u20ac\u201c at least \u00e2\u20ac\u201c to distinguish between different version of the same binary, then a helpful tool of automatic incrementing fourth number in FILEVERSION&#8217;s file version is something you cannot live without.&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1170\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[316,487,38,317,59,318,132,175,58],"class_list":["post-1170","post","type-post","status-publish","format-standard","hentry","category-utilities","tag-add-in","tag-atl","tag-c","tag-increment","tag-microsoft","tag-tool","tag-utility","tag-version","tag-visual-studio"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=1170"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1170\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}