Setting a VCProject property to default - visual-studio

I'm trying some VS2005 IDE macros to modify a large amount of projects (~80) within a solution. Some of the properties I wish to set do expose a programmatic interface to 'default', but many others do not. Is there a generic way to set such properties to their default? (eventually meaning erasing them from the .vcproj file)
Simplified example, setting some random properties:
Sub SetSomeProps()
Dim prj As VCProject
Dim cfg As VCConfiguration
Dim toolCompiler As VCCLCompilerTool
Dim toolLinker As VCLinkerTool
Dim EnvPrj As EnvDTE.Project
For Each EnvPrj In DTE.Solution.Projects
prj = EnvPrj.Object
cfg = prj.Configurations.Item(1)
toolLinker = cfg.Tools("VCLinkerTool")
If toolLinker IsNot Nothing Then
' Some tool props that expose a *default* interface'
toolLinker.EnableCOMDATFolding = optFoldingType.optFoldingDefault
toolLinker.OptimizeReferences = optRefType.optReferencesDefault
toolLinker.OptimizeForWindows98 = optWin98Type.optWin98Default
End If
toolCompiler = cfg.Tools("VCCLCompilerTool")
If toolCompiler IsNot Nothing Then
' How to set it to default? (*erase* the property from the .vcproj)'
toolCompiler.CallingConvention = callingConventionOption.callConventionCDecl
toolCompiler.WholeProgramOptimization = False
toolCompiler.Detect64BitPortabilityProblems = False
End If
Next
End Sub
Any advice would be appreciated.

For VS 2005, I believe you can use the ClearToolProperty method on VCConfiguration. The following code would accomplish this for CallingConvention (this is C#, but I'm sure something similar works for VB):
cfg.ClearToolProperty( toolCompiler, "CallingConvention" );
This would have the same effect as going into the GUI and choosing "<inherit from parent or project defaults>" for this option.
Unfortunately this seems to be deprecated in VS 2010, and I'm not sure what the new supported method is.

Related

How to temporarily block all macros from running and edit xlsm file with VBScript?

I have xlsm file which I need to edit. However, macros there block my script from editing. My code is following:
xlsm_file_name = "webADI_template_Bankbuchungen_GL.xlsm"
'opening xlsm file and setting readonly to false
set xlobj = createobject("Excel.Application")
set excel_file = xlobj.workbooks.open("C:\Users\oleynikov nikolay\Desktop\VBS Automation Scripts\processed_data\Excel Datei\"&xlsm_file_name, readonly=false)
'making changes invisible for the user
excel_file.application.enableevents = false
xlobj.Visible = false
'defining the sheet where we will be inserting our data into
set excel_sheet = excel_file.worksheets(1)
excel_sheet.cells(13,4).value = "EUR"
excel_file.application.enableevents = TRUE
xlobj.DisplayAlerts = FALSE
excel_file.save
At the end of the day, no values are added. This happens because double clicking on the cell runs the macro. I need to disable this macro, insert necessary values and then enable the macros again.
Is there a possibility to do it?
Thank you.
Try this (it seems it should work):
Returns or sets an MsoAutomationSecurity constant that represents the security mode that Microsoft Excel uses when programmatically opening files. Read/write.
MsoAutomationSecurity can be one of these MsoAutomationSecurity constants:
msoAutomationSecurityByUI. Uses the security setting specified in the Security dialog box.
msoAutomationSecurityForceDisable. Disables all macros in all files opened programmatically without showing any security alerts.
VB
Sub Security()
Dim secAutomation As MsoAutomationSecurity
secAutomation = Application.AutomationSecurity
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Application.FileDialog(msoFileDialogOpen).Show
Application.AutomationSecurity = secAutomation
End Sub
https://learn.microsoft.com/en-us/office/vba/api/excel.application.automationsecurity

How to update an repository object in uft?

I use UFT 11.53, Windows 8.1 Pro et vbscripts.
I've a question : Is it possible to add objects to an object repository automatically using VBScript?
My problem : I've an application in which I've to automate tests and qualifications. I would like to add an new object (using vbscript) to my repository object.
Below is my code which I tried:
Dim RepositoryFrom
Dim ParentObject
ObjectRepositoryPath="D:\repository.tsr"
'Creating Object Repository utility Object
Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")
'Load Object Repository
RepositoryFrom.Load ObjectRepositoryPath
Set oWebElement = WebElement(""&str) 'str = "PR1500073LRBA", it's an element of my table
Set ParentObject = Browser("fia").Page("fia_3")
RepositoryFrom.AddObject oWebElement, ParentObject, "reference"
RepositoryFrom.Save
Set RepositoryFrom = nothing
Set oWebElement = nothing
Set oParent = nothing
With this code, I've an message error :
'AddObject' - General error.
Line (63): "RepositoryFrom.AddObject oWebElement, ParentObject, "reference"".
Do you know why I've this message ?
Thanks :)

VS addin for quickly viewing preprocessed or assembly output

I'm searching for a one-click way to inspect preprocessed or assembly output.
It's just tedious to open file properties, change the respective setting, compile, go to the obj directory and open the resulting file by hand.
Does anyone know of any Visual Studio add-in, macro or whatever to automate this task?
EDIT: An extension for VS 11+ is available # https://github.com/Trass3r/DevUtils
I solved it myself by creating a nice macro.
It's way more sophisticated but basically works like this:
Imports EnvDTE
Imports Microsoft.VisualStudio.VCProjectEngine
Dim doc As EnvDTE.Document = DTE.ActiveDocument
Dim prj As VCProject = doc.ProjectItem.ContainingProject.Object
Dim file As VCFile = prj.Files.Item(doc.Name)
Dim fileconfigs As IVCCollection = file.FileConfigurations
Dim fileconfig As VCFileConfiguration = fileconfigs.Item("Release|x64")
Dim tool As VCCLCompilerTool = fileconfig.Tool
Dim asmFile = System.IO.Path.GetTempFileName + ".asm"
tool.WholeProgramOptimization = False
tool.AssemblerOutput = asmListingOption.asmListingAsmSrc
tool.AssemblerListingLocation = asmFile
fileconfig.Compile(True, True)
Dim window = DTE.ItemOperations.OpenFile(asmFile, Constants.vsViewKindCode)
Very useful in combination with AsmHighlighter.
Preprocessed file can be generated similarly with
tool.GeneratePreprocessedFile = preprocessOption.preprocessYes
' there's no separate option for this, so misuse /Fo
tool.ObjectFile = System.IO.Path.GetTempFileName + ".cpp"

Events not being raised by FileSystemWatcher in an integration test?

I'm trying to run an integration test on my class to make sure an event i expect to be raised is raised:
'integration test not unit test
<TestMethod()>
Public Sub Change_Network_File_Causes_Event_To_Be_Raised()
Dim EventCalled As Boolean
Dim deployChk = New TRSDeploymentCheck("foo")
deployChk._localFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles\SameLocalGUIDFile.txt")
AddHandler deployChk.DeploymentNeeded, Sub() EventCalled = True
deployChk.NetworkFileLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles\SameNetGUIDFile.txt")
ChangeNetworkFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles\SameNetGUIDFile.txt"))
Assert.IsTrue(EventCalled)
End Sub
Here is how i setup the FileSystemWatcher Object in my class:
Friend Property NetworkFileLocation As String
Set(value As String)
_netFileLoc = value
If File.Exists(value) Then
_watcher = New FileSystemWatcher(value.Replace(Path.GetFileName(value), String.Empty))
_watcher.EnableRaisingEvents = True
AddHandler _watcher.Changed, AddressOf OnNetworkFileChanged
End If
End Set
Get
Return _netFileLoc
End Get
End Property
Private Sub OnNetworkFileChanged(source As Object, e As FileSystemEventArgs)
If IsDeploymentNeeded() Then RaiseEvent DeploymentNeeded()
End Sub
I put a breakpoint in the OneNetworkFileChange sub. The breakpoint is never hit. I have verified the file is actually being changed in ChangeNetworkFile I even copied the code (except for hard coding the path) and copied it into a windows app which i ran during my unit test. It worked in my windows app. What am i missing here?
Finally figured it out after some testing. Well the reason EventCalled is never true above is because the "windows message pump" for the test is blocked. The event will be fired but only after the test completes (which of course is to late). So how do you fix it? Its kind of messy and i don't like it but i referenced System.Windows.Forms.dll & called Application.DoEvents()
'integration test not unit test
<TestMethod()>
Public Sub Change_Network_File_Causes_Event_To_Be_Raised()
Dim EventCalled As Boolean
Dim deployChk = New TRSDeploymentCheck("foo")
deployChk._localFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles\SameLocalGUIDFile.txt")
AddHandler deployChk.DeploymentNeeded, Sub() EventCalled = True
deployChk.NetworkFileLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles\SameNetGUIDFile.txt")
ChangeNetworkFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles\SameNetGUIDFile.txt"))
Application.DoEvents()
Assert.IsTrue(EventCalled)
End Sub
Until some tells me a better way this appears to be the solution.
Probably its the filter (string.Empty) which apparently only looks at files without an extension (that's an assumption).
Try "*.*" or something like this:
_watcher = New FileSystemWatcher(value.Replace(Path.GetFileName(value), string.Concat("*.", Path.GetExtension(value))))

VBScript: Assigning an array(2) via createobject

I'm having a problem converting this VB6 code to VBScript. I'm calling out to a COM object to create an array as EmailAddressType. Here is the working VB6 Code:
'Assign TO: addresses
Dim toAdresses(2) As New EmailAddressType
toAdresses(0).EmailAddress = "someone#whocares.com"
toAdresses(0).RoutingType = "SMTP"
toAdresses(1).EmailAddress = "someoneelse#whocares.com"
toAdresses(1).RoutingType = "SMTP"
email.ToRecipients = toAdresses
I can't seem to figure out how to convert this into VBScript. I've tried the following but just get a Type Mismatch error once I get to the email.ToRecipients = toAdresses
'Assign TO: addresses
dim toAdresses(2)
set toAdresses(0) = createobject("EWS.EWSWebSvc.EmailAddressType")
set toAdresses(1) = createobject("EWS.EWSWebSvc.EmailAddressType")
toAdresses(0).EmailAddress = "someone#whocares.com"
toAdresses(0).RoutingType = "SMTP"
toAdresses(1).EmailAddress = "someoneelse#whocares.com"
toAdresses(1).RoutingType = "SMTP"
email.ToRecipients = toAdresses
Btw this is a COM wrapper of the Exchange Web Services if that helps any.
I think the problem is that the .ToRecipients property wants an array of EmailAddressType while all you can easily get in VBScript is a Variant or array of Variants.
Looks like this API was just not built to be scriptable.
Oddly enough there is an implication it can be used from JScript though: MessageType.ToRecipients Property
I suspect they are rewriting history by gradually editing out any mention of VBScript on MSDN these days though.
Just a guess, try this
toAdresses.EmailAddress = "someone#whocares.com;someoneelse#whocares.com"
toAdresses.RoutingType = "SMTP"
email.ToRecipients = toAdresses
if it doesn't work with the ; try the ,

Resources