Reputation: 235
I'd like to know how can I get the name of the solution that the XAML Build Definition is using.
For instance in the configuration of my Build Defnition I have this path to chose which solution I want to apply this Build Definition: $/test/SolutionName/SolutionName.sln
How can I get "SolutionName" for my Activity Code, using C# code.
EDIT: My variable, what can I put as Default yield?
The code:
public InArgument<string> BuildSettings { get; set; }
....
string nameSolutionAuto = System.IO.Path.GetFileNameWithoutExtension(this.BuildSettings.ProjectsToBuild[0]);
Upvotes: 0
Views: 916
Reputation: 33698
The projects/solutions info is stored in ProjectsToBuild variable, so you just need to pass this variable value to your Activity (InArgument) and get the solution or project name by this code (InArgument variable:solutionPaths):
foreach(string solution in solutionPaths)
{
Console.WriteLine(solution.Split(new char[] { '/' }).Last());
}
An example to display selected solutions/projects in build definition to build log:
Upvotes: 1
Reputation: 8343
Your Activity needs a property of type BuildSettings, which you set with the value of the BuildSettings
variable.
In the Activity code, examine the content of the ProjectsToBuild property and extract the name of the solution file, e.g. System.IO.Path.GetFileNameWithoutExtension(this.BuildSettings.ProjectsToBuild[0])
.
EDIT
The BuildSettings
variable is defined globally, no need to re-define it.
The BuildSettings
property should be
public InArgument<Microsoft.TeamFoundation.Build.Workflow.Activities.BuildSettings> BuildSettings { get; set; }
and you have to assign the BuildSettings
variable to this property in the XAML Property Window.
To use it the code should be more like
var buildSettings = GetValue<Microsoft.TeamFoundation.Build.Workflow.Activities.BuildSettings>(this.BuildSettings);
string nameSolutionAuto = System.IO.Path.Get
FileNameWithoutExtension(buildSettings.ProjectsToBuild[0]);
Upvotes: 2