I'm trying to figure out how to close the loop in our build process where we apply a version number to the AssemblyInfo.* files as part of the build process.
We are in the midst of migrating from on-premise tfs to visual studio team services. Many of our current on-premise builds update the version number to keep it in sync with the build number and additionally check those files back into source control during the build.
I've successfully used the script located on msdn as an example to start customizing the build process.
I'm now attempting to check the files back into source control but I'm receiving the error:
#[error]TF30063: You are not authorized to access https://subdomain.visualstudio.com/DefaultCollection.
#[error]Process completed with exit code 100 and had 1 error(s) written to the error stream.
I'm currently using tf.exe to attempt to do this. First get the path to the tool at the top of the powershell script;
# get the tf command line tool path
$tfexe = [System.IO.Path]::GetFullPath($env:VS140COMNTOOLS + "..\..\common7\ide\tf.exe")
if (-Not (Test-Path $tfexe))
{
Write-Error "Could not find tf.exe at '$tfexe'"
exit 1
}
else
{
Write-Host "Found tf.exe at '$tfexe'"
}
Then modify the loop to checkout the file and then check the files back in.
# Apply the version to the assembly property files
$files = gci $Env:BUILD_SOURCESDIRECTORY -recurse -include "*Properties*","My Project" |
?{ $_.PSIsContainer } |
foreach { gci -Path $_.FullName -Recurse -include AssemblyInfo.* }
if($files)
{
Write-Host "Will apply $NewVersion to $($files.count) files."
foreach ($file in $files) {
#Write-Host "Attempting to checkout file '$file'"
& ($tfexe) vc checkout $file
$filecontent = Get-Content($file)
attrib $file -r
$filecontent -replace $VersionRegex, $NewVersion | Out-File $file
Write-Host "$file.FullName - version applied"
}
# Checkin pending changes together
##[error]TF30063: You are not authorized to access https://subdomain.visualstudio.com/DefaultCollection.
##[error]Process completed with exit code 100 and had 1 error(s) written to the error stream.
Write-Host "Attempting to checkin files"
$comment = "Applied $NewVersion to $($files.count) files. ***NO_CI***"
& ($tfexe) vc checkin /comment:"$comment" /noprompt
}
Is this the proper way to be doing this? If the build service is not authorized to access, how the heck can it GET the code, compile it, and then POST the artifact somewhere?
What is TFS Check-in Policy? Check-in policy enforces constraints every time when files are checked into source control.
Right-click your project or project suite in the Project Explorer and then click Source Control > Check In. Click Check In on the Source Control toolbar (if the toolbar is hidden, right-click the toolbar area and select Source Control). Team Explorer's Check In dialog will appear.
The lock means that the item is checked in, and the + means that an add operation is pending for the item.
In Microsoft Visual Studio, click Tools > Options. Go to Source Control > Jazz Source Control > Check-in Policies. Select the Auto check-in local changes check box and click OK.
I would not recommend to check in the assembly version every time, instead I'd recommend to use the [assembly: AssemblyVersion("1.2.*")]
wildcard support (and I remove the [AssemblyFileVersion]
so it's automatically matching.
Checking in the changed files after the build has issues in a number of ways:
**NO_CI**
changesetsI created a new build task which will allow you to check-in files using a task:
Add it to your visualstudio team foundation services or TFS 2015 instance using the tfx
console:
tfx build tasks upload -taskpath path\to\project\root
I'm still working on a way to pend adds and deletes, but I'm running into issues with the Client Object Model somehow not pending anything other than edits.
it looks like calling tf add
and tf delete
will actually work in the build script in combination with this checkin task.
For more information:
As I commented before.
I would rather discard the changes on
AssemblyInfo.*
files than check them into the source control.
In my case I use 1.$(date:yy).$(date:MMdd)$(rev:.r)
as a build number format
So I will never read back the version from the a AssemblyInfo.*
files, so what is the point of saving that information?
The build number format will generate the version again regardless the value stored of the AssemblyInfo.*
If you want to sync source code with an specific version you could use the same build number format to label the source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With