I am getting the Object Reference Error (above) when implementing the following piece of code taken from the Microsoft Developers Netork (https://msdn.microsoft.com/en-us/library/ms404233(v=vs.100).aspx)
SolutionBuild2 slnbld2 = (SolutionBuild2)DTE.Solution.SolutionBuild;
//Save changes to all projects and clean.
foreach (Project proj in DTE.Solution.Projects)
{
proj.Save();
}
slnbld2.Clean(true);
foreach (Project proj in DTE.Solution.Projects)
{
Am I missing something or should I easily be able to implement it as written? Any help is greatly appreciated!
EDIT
Public Module PublishAllProjects
Sub PublishAllProjectsInSolution()
' Before using this macro, the certficate and security zone must be set.
' You can do this by publishing the projects using the VS IDE.
Dim slnbld2 As SolutionBuild2 = CType(DTE.Solution.SolutionBuild, SolutionBuild2)
'Save changes to all projects and clean.
For Each proj As Project In DTE.Solution.Projects
proj.Save()
Next
slnbld2.Clean(True)
For Each proj As Project In DTE.Solution.Projects
'Verify project is a windows application or console application before continuing
Dim outputType As Integer = proj.Properties.Item("OutputType").Value
If outputType <> 0 AndAlso outputType <> 1 Then
Continue For
End If
'GenerateManifests and SignManifests must always to true for publishing to work.
proj.Properties.Item("GenerateManifests").Value = True
proj.Properties.Item("SignManifests").Value = True
proj.Save()
slnbld2.BuildProject(proj.ConfigurationManager.ActiveConfiguration.ConfigurationName, proj.UniqueName, True)
'only publish if build was successful.
If slnbld2.LastBuildInfo <> 0 Then
MsgBox("Build failed for " & proj.UniqueName)
Else
slnbld2.PublishProject(proj.ConfigurationManager.ActiveConfiguration.ConfigurationName, proj.UniqueName, True)
If slnbld2.LastPublishInfo = 0 Then
MsgBox("Publish succeeded for " & proj.UniqueName)
Else
MsgBox("Publish failed for " & proj.UniqueName)
End If
End If
Next
End Sub
End Module
The above code (sourced from https://msdn.microsoft.com/en-us/library/ms404233(v=vs.100).aspx) is VB but I have made an attempt to transcribe it to C#. I am hoping to be able to use it to be able to point to a solution on a file location and publish it.
When I transcribed it I got the error on every reference to DTE.Solution having imported the References for EnvDTE. I am hoping this is just a simple issue to overcome. I am relatively new to C# so can imagine (HOPE) it may well be! Chris