VS addin for quickly viewing preprocessed or assembly output - visual-studio-2010

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"

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

Word document mysteriously write protected?

I am trying to do a find and replace operation on several Word documents in a folder. I wrote the following VBScript to do that:
Option Explicit
Dim Word, Document, FolderPath, FileSystem, FileList, File, Doc, InfoString
Const ReadOnly = 1
Const wdFindContinue = 1
Const wdReplaceAll = 2
Const wdOriginalDocumentFormat = 1
Set FileSystem = CreateObject("Scripting.FileSystemObject")
FolderPath = FileSystem.GetAbsolutePathName(".")
Set FileList = FileSystem.GetFolder(FolderPath).files
Set Word = CreateObject("Word.Application")
Word.Visible = False
Word.DisplayAlerts = False
For Each File in FileList
If LCase(Right(File.Name,3)) = "doc" Or LCase(Right(File.Name,4)) = "docx" Then
If File.Attributes And ReadOnly Then
File.Attributes = File.Attributes - ReadOnly
End If
Set Doc = Word.Documents.Open(File.Path,,True)
' find and replace stuff
End If
Next
Word.Documents.Save True, wdOriginalDocumentFormat
Word.Quit
MsgBox("Done")
Problem is, when it reaches the line Word.Documents.Save, a Save As dialog box always pops up. If I click Cancel, I get an error from Windows Script Host saying the file is write protected, even though it is not shown as write protected if I open the Properties dialog in File Explorer. If I click save, I am prompted to save all the other files too. What is the problem here?
I have a suspicion that it is caused by the Word documents being very old, like from the 1990s.
Set Doc = Word.Documents.Open(File.Path,,True)
and look at the docs from Object Browser.
Function Open(FileName, [ConfirmConversions], [ReadOnly], [AddToRecentFiles], [PasswordDocument], [PasswordTemplate], [Revert], [WritePasswordDocument], [WritePasswordTemplate], [Format], [Encoding], [Visible], [OpenAndRepair], [DocumentDirection], [NoEncodingDialog]) As Document
Member of Word.Documents
So the True says to open Read Only. This is Word's read only, nothing to do with the file.

TFS 2010 tracking build definition changes?

Is there a way to track changes to a build definition in TFS 2010? Please go to 'Team Explorer > ProjectName > Builds' in visual studio to see what I am talking about. You need to have access to a TFS server in order to see what I am referring to. Now once you are in the Team Explorer> ProjectName > Builds, you can create a build definition to compile your csproj or sln files on TFS. What I am wondering is, Is there a way to version these build definitions if I do any changes to existing ones or add a new one?
I got into the same issue when someone from the team modified the Build Definition, I tried to find all the available option but found none except Xeam Build Definition Extension which is only supported VS 2012 onward and has some downsides, so finally to get the immediate work around I wrote a small app which returns the Last Modified By and Last Modified Date and the complete Build Definition details which you can compare with previous version to find what got changed.
Imports Microsoft.TeamFoundation.Build.Client
Private Const RootFolder As String = "C:\TFS Utility Reports\"
''' <summary>
''' To Get the Build Definition Details
''' </summary>
''' <param name="teamProjectName"></param>
''' <param name="buildDefinitionName"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function GetBuildDefinitionDetails(teamProjectName As String, buildDefinitionName As String) As String
Dim buildDefinitionSummary As String = Nothing
Dim buildDefinitionDetails As String = Nothing
Dim reportPath As String = RootFolder & "Build Definitions\" & buildDefinitionName
Dim buildDefinitionDetailsFileName As String = reportPath & "\" & buildDefinitionName & "_" & Date.Now.ToString(CultureInfo.CurrentCulture).Replace("/", String.Empty).Replace(":", String.Empty) & ".txt"
Dim buildService = CType(TfsTeamProjectCollection.GetService(GetType(IBuildServer)), IBuildServer)
Dim buildDefinition As IBuildDefinition = buildService.GetBuildDefinition(teamProjectName, buildDefinitionName)
If buildDefinition IsNot Nothing Then
GetAllBuildDefinitions(teamProjectName)
buildDefinitionSummary = buildDefinition.ToString()
UpdateFile(buildDefinitionSummary, buildDefinitionDetailsFileName, reportPath)
If buildDefinition.Workspace IsNot Nothing Then
buildDefinitionDetails = String.Format(CultureInfo.CurrentCulture, "Last Modified By: {0}, Last Modified Date: {1}",
buildDefinition.Workspace.LastModifiedBy,
buildDefinition.Workspace.LastModifiedDate)
End If
End If
Return buildDefinitionDetails
End Function
''' <summary>
''' Generate Log/Summary/Report
''' </summary>
''' <param name="lineToWrite"></param>
''' <param name="filePath"></param>
''' <param name="folderPath"></param>
''' <remarks></remarks>
Private Shared Sub UpdateFile(ByVal lineToWrite As String, ByVal filePath As String, ByVal folderPath As String)
Dim strFileName As String = String.Empty
lineToWrite = lineToWrite.Trim()
strFileName = filePath
Dim di As IO.DirectoryInfo = New IO.DirectoryInfo(folderPath)
If Not di.Exists Then
di.Create()
End If
Dim streamWriter As New StreamWriter(strFileName, True, System.Text.Encoding.ASCII)
Try
Dim strOutput As String
strOutput = lineToWrite.ToString
streamWriter.WriteLine(strOutput)
Catch ex As Exception
Throw
Finally
streamWriter.Dispose()
End Try
End Sub
There is no way to track changes to a build definition. If you have multiple branches / versions you need to build I suggest creating a different build definition.
Some of the properties can be set when you queue the build, so if you want a CI build that does not copy it's output to the drop server, you can have that, but then if you want to deploy a version you can set a drop folder when you queue the build.
In the TFS Power Toys you get a "Clone Build Definition" context menu so you can copy builds easier if you have a lot of settings you want to keep similar.
There is a way. There is this tool in the vsgallery:
http://visualstudiogallery.msdn.microsoft.com/ec36f618-d122-48a3-8236-7d9cd19791ee
I used it with tfs2012. I don't know if it works with tfs2010

Converting Microsoft XML file format to Excel file

I have requirement that I'm not really sure on how to go about it. I have a file Doc.xml, this is in Microsoft XML format. I need to create a VB script that will change/convert the Doc.xml to Doc.xlsx, so when the user tries to open the file it will open as an Excel file.
One of the requirements is that this script will be run from the Windows Scheduler.
Any ideas or recommendation will be really appreciated.
This is the script I created and is working, but when I try to change the SaveAs extension to ".csv" the file is not being saved correctly. I guess I need to find out what the code is for saving in CSV.
Dim objXLApp, objXLWb, objXLWs
Set objXLApp = CreateObject("Excel.Application")
objXLApp.Visible = True
Set objXLWb = objXLApp.Workbooks.Open("C:\Users\jmejia\Desktop\XML_F\ZOOSHR_130622.xml")
'Do nothing with File, just open it to be save agains as a new file format
objXLWb.SaveAs "C:\Users\jmejia\Desktop\XML_F\ZOOSHR_130622.xlsx", 51
objXLWb.Close (False)
Set objXLWs = Nothing
Set objXLWb = Nothing
objXLApp.Quit
Set objXLApp = Nothing
If your file was created and exported from Excel > 2006? then it will have the tags in it such that double clicking in explorer on a windows machine with any Excel that supports xml format will automatically open it in Excel.
Your file is likely to start with something like:
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
Const xlXLSX = 51
REM 51 = xlOpenXMLWorkbook (without macro's in 2007-2013, xlsx)
REM 52 = xlOpenXMLWorkbookMacroEnabled (with or without macro's in 2007-2013, xlsm)
REM 50 = xlExcel12 (Excel Binary Workbook in 2007-2013 with or without macro's, xlsb)
REM 56 = xlExcel8 (97-2003 format in Excel 2007-2013, xls)
dim args
dim file
dim sFile
set args=wscript.arguments
dim wshell
Set wshell = CreateObject("WScript.Shell")
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open( wshell.CurrentDirectory&"\"&args(0))
objExcel.DisplayAlerts = FALSE
objExcel.Visible = FALSE
objWorkbook.SaveAs wshell.CurrentDirectory&"\"&args(1), xlXLSX
objExcel.Quit
Wscript.Quit

Setting a VCProject property to default

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.

Resources