Prevent installation of VSTO Addin on build - vsto

How to prevent background installation of VSTO Outlook Addin on build in Visual Studio?
Addin installed when build/rebuild project or solution. Installed addin is not even shown in Programs and Features.

Addin installed when build/rebuild project or solution. Installed addin even not shown in Programs and Features.
The add-in is not actually installed. It is registered, see Registry Entries for Application-Level Add-Ins for more more information.
You may try to add a post-build action to remove the registry keys to prevent it from loading (or just change the LoadBehavior key).

I'm targeting a specific purpose. My client build machine projects fail when they build the same VSTO-projects from different Git-branches simultaneously.
VSTO-project tries to register its MS Office add-in to the Windows Registry during building.
If some VSTO-projects are building simultaneously then a Windows async exception can be thrown. See the exception below.
Of course won't see this error in Visual Studio. Commonly, you're building one solution at a time. This is the source of this evil bug.
With a due respect to the question's authors and future comers, let me post some "preliminary to build-machines" solutions.
I can't test them for an VSTO Outlook Add-in project. But they are tested for MS Word and Excel add-ins.
Actually, the Outlook project is slightly special. If something goes wrong with it, then you can learn MSBuild and dig farther out of
C:\Program Files (x86)\Microsoft Visual Studio\20<XX>\Professional\MSBuild\Microsoft\VisualStudio\v<XX>.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets
Hack MSBuild Task.
We will be using MSBuild Inline Tasks approach.
Let's do it for MS Word and Excel Add-ins.
For the Outlook VSTO, you have to override more tasks. Probably the RegisterFormRegions, FindRibbons, etc. I just can't test it.
In the Solution Explorer, click "Clean" on your VSTO Add-in project to delete previous registrations.
then do "Unload Project" on your project.
Edit {You-Project-Name}.csproj from the context menu on you project in the Solution Explorer.
Find <Import Project="$(VSToolsPath)\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets"
Before (!!!) this Import row, insert the following XML of my inline MSBuild task.
<UsingTask
TaskName="SetOffice2007AddInRegistration"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<Url ParameterType="System.String" Required="false"/>
<AddInName ParameterType="System.String" Required="false"/>
<OfficeApplication ParameterType="System.String" Required="false"/>
<FriendlyName ParameterType="System.String" Required="false"/>
<Description ParameterType="System.String" Required="false"/>
<LoadBehavior ParameterType="System.String" Required="false"/>
<Unregister ParameterType="System.String" Required="false"/>
<SolutionID ParameterType="System.String" Required="false"/>
<IsDocument ParameterType="System.String" Required="false"/>
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage(MessageImportance.High, "$(MSBuildProjectName) project - Overriding of SetOffice2007AddInRegistration to prevent the project's MS Office Add-in isntallation (registration)!");
]]>
</Code>
</Task>
</UsingTask>
Click Reload Project on your Add-in's project.
That's it.
You can also use C# and mock or derive from the existing C# class of SetOffice2007AddInRegistration task. But this will be quite verbose for the StackOverflow.
Hack the VisualStudioForApplicationsBuild Target
Everything is changing and VSTO is rather dead than alive.
So, why don't you copy <Target Name="VisualStudioForApplicationsBuild">...</Target> from the mentioned above Microsoft.VisualStudio.Tools.Office.targets file and override it in your VSTO add-in project file?
Put it below the <Import Project="$(VSToolsPath)\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" and do what ever you want.
Hack the RegisterOfficeAddin MSBuild target
This is for MS Word and Excel add-ins only.
As described above, find <Import Project="$(VSToolsPath)\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets".
and put below (!!!)
<Target Name="RegisterOfficeAddin" Condition ="'$(VSTO_ProjectType)' == 'Application'" />
More, More
Actually, there are other MSBuild approaches. But who bothers?
Hack on my laptop only
Sorry, this is out of my orbit, really :)
But knowing MSBuild, you can do it for a Windows login name or for an exact PC name. Just for fun. Why not use the MSBuild Inline Tasks as described above?
Build Machines
Let's prevent VSTO Add-ins installation/registration caused by VSTO Add-in project building.
The following works for MS Word and Excel VSTO Add-in projects.
Add -p:Disable_RegisterOfficeAddin=disable to your invocation of MSBuild
CMD example
CALL "%env_manager%\MSBuild_Wrapper_VS2017.bat"^
MySolution.sln^
-target:Build^
-p:Configuration=Release^
-p:Disable_RegisterOfficeAddin=disable^
-verbosity:%env_MsBuild_verbosity%^
-maxCpuCount
Edit ".csproj" file of your VSTO Add-in project.
find <Import Project="$(VSToolsPath)\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets"
row and put below (!!!) it the following XML.
<!-- Prevent VSTO MS Office add-ins installation/registering during building of VSTO-projects on build machines. -->
<Target Name="RegisterOfficeAddin" Condition ="'$(VSTO_ProjectType)' == 'Application'">
<Message Text="RegisterOfficeAddin target is redefined in $(MSBuildProjectName) project" Importance="high" />
<SetOffice2007AddInRegistration
Url="$(AbsolutePathToTheDeploymentManifest)"
AddInName="$(TargetName)"
OfficeApplication="$(OfficeApplication)"
FriendlyName="$(FriendlyName)"
Description="$(OfficeApplicationDescription)"
LoadBehavior="$(LoadBehavior)"
Condition="'$(Disable_RegisterOfficeAddin)' != 'disable'"
/>
<Message Text="SetOffice2007AddInRegistration task is suppressed in $(MSBuildProjectName) project" Condition="'$(Disable_RegisterOfficeAddin)' == 'disable'" Importance="high" />
<Message Text="as Disable_RegisterOfficeAddin parameter is $(Disable_RegisterOfficeAddin)" Condition="'$(Disable_RegisterOfficeAddin)' == 'disable'" Importance="high" />
</Target>
The Exception
Let me provide you with my full exception from VSTO-project building
The "SetOffice2007AddInRegistration" task failed unexpectedly.
System.IO.IOException: Illegal operation attempted on a registry key that has been marked for deletion.
BTW, there are no "Clean Project" commands in my build processes.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: The "SetOffice2007AddInRegistration" task failed unexpectedly. [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: System.IO.IOException: Illegal operation attempted on a registry key that has been marked for deletion. [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str) [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind) [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.VisualStudio.Tools.Office.Runtime.AddInRegistryKeyManager.CreateKey(RegistryKey rootKey, String url, String addInName, String officeApplication, String friendlyName, String description, Int32 loadBehavior) [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.VisualStudio.Tools.Office.Runtime.AddInRegistryKeyManager.RegisterAddIn(OfficeSolutionMetadata parser) [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.VisualStudio.Tools.Office.Runtime.AddInRegistryKeyManager.RegisterAddIn(Uri manifestUri, String addInName, String officeApplication, String friendlyName, String description, Int32 loadBehavior, String compatibleFrameworkXML, Boolean runLocal) [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.VisualStudio.Tools.Office.BuildTasks.SetOffice2007AddInRegistration.Execute() [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Build-Machine\My\Build\Source\MyAddin.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(314,9): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() [C:\Build-Machine\My\Build\Source\MyAddin.csproj]

Related

Visual Studio - Could not copy the file "obj\Debug\[file].exe" because it was not found

So, I'm trying to build a project I just installed Visual Studio to build this specific project (it is in vb6 so I needed to use the Visual Basic tools extension because i had Visual Studio 2015 installed). I have no programming knowledge on this area, only web.
And when I try to build it it gives me this error:
------ Build started: Project: Proyecto1, Configuration: Debug x86 ------
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(3812,5):
error MSB3030: Could not copy the file "obj\Debug\Proyecto1.exe"
because it was not found. Done building project "Proyecto1.vb6proj" --
FAILED.
Build FAILED.
Then I click on the error and it send me to that piece of code
<!-- Copy the build product (.dll or .exe). -->
<Copy
SourceFiles="#(IntermediateAssembly)"
DestinationFolder="$(OutDir)"
SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Retries="$(CopyRetryCount)"
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
Condition="'$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'">
<Output TaskParameter="DestinationFiles" ItemName="MainAssembly"/>
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
<Message Importance="High" Text="$(MSBuildProjectName) -> #(MainAssembly->'%(FullPath)')" Condition="'$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)'!='true'" />
I already saw the existent questions for this problem and the solutions didn't worked for me.
In my case it was like #Hans says it was my Antivirus fault (Avast) I disabled it to test if that was the problem, deleted the bin and debug folders and re-opened the solution and it worked perfectly.
P.D. Remember to add you solution folder to your antivirus exclusions.

Visual Studio 2015 not able to locate custom report assembly

I am getting this error in Visual Studio 2015 report project. This project builds fine in VS2012. I suspect VS2015 is not able to locate a custom assembly at compile time. But I am not sure which all paths it is searching.
Error [rsErrorLoadingCodeModule] Error while loading code module:
‘xxxx.Reports.SDK, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null’. Details: Could not load file or assembly
'xxxx.Reports.SDK, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. The system cannot
find the file specified.
I have already deployed my custom assembly on these locations but it did not help.
- C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies
- C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies
- C:\Program Files\Microsoft SQL Server\MSRS11.MSSQLSERVER\Reporting
Services\ReportServer\bin
- C:\Program Files (x86)\MSBuild\14.0\Bin
- C:\Program Files (x86)\MSBuild\12.0\Bin
Please help me resolve this issue. Thanks.
You should deploy your custom assembly to the VS2015 Folder for private assemblies (in standard installations: "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies"

TFS Build fails with Exec task in upgraded MSBuild build script after TFS 2012 upgrade

We have a project where we customized the TFS build script in TFS 2008, back when the builds were MSBuild based, instead of Workflow files. This customized script uses the <Exec> task to call NAnt to do some packaging.
After migrating our TFS 2010 installation to a new server and upgrading to TFS 2012, that line in the TFSBuild.proj file is causing an error:
Target "AfterCompile: (TargetId:321)" in project "C:\Builds\2\Proj\Continuous Integration (Proj)\BuildType\TFSBuild.proj" (target "Compile" depends on it):
Using "Exec" task from assembly "Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "Exec" (TaskId:209)
Task Parameter:Command=C:\Tools\NAnt\bin\Nant.exe (TaskId:209)
Task Parameter:WorkingDirectory=..\Sources\ (TaskId:209)
Command: (TaskId:209)
C:\Tools\NAnt\bin\Nant.exe (TaskId:209)
C:\Builds\2\Proj\Continuous Integration (Proj)\BuildType\TFSBuild.proj(225,5): error MSB6003: The specified task executable "cmd.exe" could not be run. The directory name is invalid
Done executing task "Exec" -- FAILED. (TaskId:209)
Done building target "AfterCompile" in project "TFSBuild.proj" -- FAILED.: (TargetId:321)
That line looks like this:
<Target Name="AfterCompile">
<Exec Command="C:\Tools\NAnt\bin\Nant.exe" WorkingDirectory="..\Sources\" />
<!-- ... -->
</Target>
Check your working directory. I expect this to point to a non existing location.
Specifically, the default Sources and Binaries directory names were changed in TFS 2012 to src and bin. Use the properties $(SourcesSubdirectory) and $(BinariesSubdirectory) to get the correct value.

Localize WiX installer which uses the Firewall extension

I've got a WiX installer project which uses MSBuild to generate the MSI file. The WXS file includes the WiX firewall extension:
xmlns:fire="http://schemas.microsoft.com/wix/FirewallExtension"
I've defined two cultures in the MSBuild file with the following definition:
<PropertyGroup>
...
<Cultures>en-us;no-no</Cultures>
</PropertyGroup>
I've also added the translated resources:
<ItemGroup>
<EmbeddedResource Include="lang\Firewall_no-no.wxl" />
<EmbeddedResource Include="lang\WixUI_no-no.wxl" />
</ItemGroup>
These represents translation to Norwegian for the Firewall extension and the WixUI extension. When I run the build it succeeds with the en-us part, but the no-no part fails with the following error messages:
C:\delivery\Dev\wix30_public\src\ext\FirewallExtension\wixlib\FirewallExtension.wxs(19):
error LGHT0102: The localization variable !(loc.WixSchedFirewallExceptionsInstall)
is unknown. Please ensure the variable is defined.
....
Couple of issues: I don't know where the C:\delivery directory comes from. I don't have such a directory. The localization variables referenced in the error message have been translated in the Firewall_no-no.wxl file.
When I run MSBuild with more detailed information I see the following output right before the error message:
Task "Light"
Command:
C:\Program Files (x86)\Windows Installer XML v3\bin\Light.exe -cultures:no-no
-ext "C:\Program Files (x86)\Windows Installer XML v3\bin\WixUIExtension.dll"
-ext "C:\Program Files (x86)\Windows I nstaller XML v3\bin\WixUtilExtension.dll"
-ext "C:\Program Files (x86)\Windows Installer XML v3\bin\WixFirewallExtension.dll"
-loc lang\Firewall_no-no.wxl -loc lang\WixUI_no-no.wxl
-out F:\Projects\MyProd\MyProj\Installer\bin\Debug\no-no\MyInstaller.msi
-pdbout F:\Projects\MyProd\MyProj\Installer\bin\Debug\no-no\MyInstaller.wixpdb
obj\Debug\MyProj.wixobj
As the details show, the MSBuild task results in having two -loc parameters to the Light executable. Not sure if that would be the reason for this problem. Any ideas on how to solve this?
It seems that the reason for this error was very simple. I got the exception because I hadn't changed the Culture="no-no" attribute in the WixLocalization tag. Setting this value made the errors disappear.

Having trouble getting MSBuild and MSBuildCommunityTasks (VSS) to work together

I am trying to learn how to do certain source control tasks with VSS and MSBuildCommunityTasks, like how to use tasks like GetVSS and VssLabel? Docs don't make this clear. And when I poke a stick at it to see if the error messages can tell me anything, it isn't really very clear what to do then, either. Let me show what I'm doing and what I'm getting -- I hope someone can point me in the right direction.
Project is written in C# using VS2005. Here's the MSBuild project file source:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<Target Name="GetLatestVersionVSS">
<VssGet DatabasePath="C:\VSS\Astronom_VSS"
Path="$/Astronom_VSS"
LocalPath="C:\VisualStudioSource\AstronomySolution\Astronom" UserName="build" Password="build" />
</Target>
<Target Name="Compile" DependsOnTargets="GetLatestVersionVSS">
<MSBuild Projects="Astronomer.x.csproj" />
</Target>
</Project>
I get error messages as follows:
Target GetLatestVersionVSS:
C:\Documents and Settings\michaelc\My Documents\Visual Studio 2005\Projects\Astronom\Astronomer\msbuild_UseVSS.xml(7,5):
error MSB4018: The "VssGet" task failed unexpectedly.
C:\Documents and Settings\michaelc\My Documents\Visual Studio 2005\Projects\Astronom\Astronomer\msbuild_UseVSS.xml(7,5):
error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly
'Microsoft.VisualStudio.SourceSafe.Interop, Version=5.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
or one of its dependencies. The system cannot find the file specified.
C:\Documents and Settings\michaelc\My Documents\Visual Studio 2005\Projects\Astronom\Astronomer\msbuild_UseVSS.xml(7,5):
error MSB4018: Filename: 'Microsoft.VisualStudio.SourceSafe.Interop, Version=5.2.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'
...And so on.
It occurs to me that I might need to put some sort of Import item in there to point to VSS, specifically to point to Microsoft.VisualStudio.SourceSafe.Interop, but I cannot find a .dll file by that name, and it is not in the list of components in the .NET tab of the Add Reference dialog in Visual Studio.
OK, I am answering my own question.
MSBuildCommunityTasks requires Visual Source Safe 2005, which ships with VS2005. We are, however, still using VSS 6.0d, and MSBuildCommunityTasks does not work with it. The developer's guide for the tasks states:
Developer's Guide for http://msbuildtasks.tigris.org/
=====================================================
Build Environment Prerequisites
------------------------------
- .NET2.0
- MSBuild; typically already installed as part of .NET2.0,
for example in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe
- NUnit 2.2.X (http://www.nunit.org/);
necessary to run the tests
- Microsoft Visual SourceSafe(R) 2005;
the library Microsoft.VisualStudio.SourceSafe.Interop gets referenced
- NDoc 1.3 (http://ndoc.sourceforge.net/)
additionally configure NDoc to use .NET2; see
http://ndoc.sourceforge.net/wiki/dotNet_2.0_Support
- Microsoft Visual Studio 2005 as IDE