We are using TFS 2013 to manage our source code for a Windows Store app. Unfortunately, it looks like we have to change the version number manually. This is tedious and easy to forget. If we use the wrong build twice, we have to take extra steps to deploy. Is there a way to set version numbers when the Build server builds?
You need to execute a PowerShell pre-build on the build server to update the build number. There is an example script as part of the TFS Community Build Tools.
https://curah.microsoft.com/8047/run-scripts-in-your-team-foundation-build-process
Look for ApplyVersionToAssemblies.ps1. You will have to customise to update any manafest files you need...
I found the solution. This will modify the version number in the appmanifest. I'm not sure of the source, if anyone would post the source, I will add this to this comment.
This is a powershell script that I added to the project source control and set it to run pre-build. This worked like a charm for each build for me. This is exactly what I wanted it to do.
# get the build number, we assume the format is Myproject.Main.CI_1.0.0.18290
# where the version is set using the TFSVersion custom build activity (see other posts)
$buildnum = $env:TF_BUILD_BUILDNUMBER.Split('_')[1]
# get the manifest file paths
$files = Get-ChildItem -Path $env:TF_BUILD_BUILDDIRECTORY -Filter "Package.appxmanifest" -Recurse
foreach ($filepath in $files)
{
Write-Host "Updating the Store App Package '$filepath' to version ' $buildnum '"
# update the identity value
$XMLfile=NEW-OBJECT XML
$XMLfile.Load($filepath.Fullname)
$XMLFile.Package.Identity.Version=$buildnum
# set the file as read write
Set-ItemProperty $filepath.Fullname -name IsReadOnly -value $false
$XMLFile.save($filepath.Fullname)
}
Related
I am using Magic Chunks(https://marketplace.visualstudio.com/items?itemName=sergeyzwezdin.magic-chunks) to replace appsettings.json file based on environment build in my VSTS build.
This works on windows build agent machine for android, but crashes on mac build agent machine, due to not supported:
https://github.com/sergeyzwezdin/magic-chunks/issues/43
Basically what plugin does it allows to replace appsettings.json values before build task happens in vsts build:
Is there any working alternative for Mac?
I tried token replacement from here https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens which is easy if you use place holders to replace, but I don't use placeholders, since appsettings.json already has legit values for parameters.
My other option is to create old school appsettings.{build}.json now but I kind of don't want that.. But I would rather stay with one file only.
I ended up using powershell script. After adding PS task into build I've chosen inline script:
$a = Get-Content -Path appsettings.json | ConvertFrom-Json
$a.AppSettings.ApiUrl = "$(ApiUrl)"
$a | ConvertTo-Json | Set-Content -Path appsettings.json
Initially I created an application that I completely rewrite in a second version. It is a complete different Visual studio solution.
Now I would like that its Setup installer uninstall the previous version but because it was not created using the same solution, the automatic uninstallation of previous version does not work.
Is there any way to force the installer to uninstall certain application based on product name or product code?
I found a WMIC command that works when run from command line
wmic product where name="XXXX" call uninstall /nointeractive
So I created a VBS script which execute a bat file containing the WMIC code and I added it to the Setup project
dim shell
set shell=createobject("wscript.shell")
shell.run "uninstallAll.bat",0,true
set shell=nothing
but when I run the result MSI, it fires an error 1001, meaning that a service already exists. , in other words the uninstallation didn't work.
The old program is still present and they create a service with the same name. :/
any suggestion?
There are 2 options:
You can increase the version of MSI project so it will treat as upgrade and it will not throw any error while installing.
another way out is the write some in the installer project as follows:
protected override void OnBeforeInstall(IDictionary savedState)
{
//Write uninstall powershell script
//installutil /u <yourproject>.exe
using (PowerShell PowerShellInstance = PowerShell.Create())
{
PowerShellInstance.AddScript("");
PowerShellInstance.AddParameter("");
}
PowerShellInstance.Invoke();
}
Note: This InstallUtil is available with the .NET Framework, and its path is %WINDIR%\Microsoft.NET\Framework[64]\<framework_version>.
For example, for the 32-bit version of the .NET Framework 4 or 4.5.*, if your Windows installation directory is C:\Windows, the path is C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe.
For the 64-bit version of the .NET Framework 4 or 4.5.*, the default path is C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe
I decided to go for the option of introducing c# code in the project installer. Firstly I added the reference for System.Management.Automation via nuget
https://www.nuget.org/packages/System.Management.Automation
After this, I just created a string variable containing the PS code I need to uninstall several programs with a similar name.
string unInstallKiosk = #"$app = get-WMIObject win32_Product -Filter ""name like 'KIOSK'""
foreach ($program in $app){
$app2 = Get-WmiObject -Class Win32_Product | Where -Object { $_.IdentifyingNumber -match ""$($program.identifyingNumber)""
}
$app2.Uninstall()}";
and passed this variable to the method PowerShellInstance.AddScript()
PowerShellInstance.AddScript(unInstallKiosk);
The installation ends but the uninstallation simply dont happens.
anyone has an idea how to solve this?
I have Ubuntu 16.04 and I have to download the C# extension for Visual Studio Code, once I installed it, It doesn't make effect. Then, vscode give me and advice that I should open vscode with admin privileges to make effect of the extensions installed, so I wrote on my terminal:
sudo code .
but it doesn't work, the terminal throws me:
It is recommended to start vscode as a normal user. To run as root, you must specify an alternate user data directory with the --user-data-dir argument.
but I don't know how to specify an alternate user data directory. I was searching how to do that in visual studio code docs but there is not a reference for this issue. If you know how to open with admin privileges in linux please help me.
To run with superuser:
$ sudo code --user-data-dir=~/root
By the way you will be able to run without setting params in the upcoming patch 1.5.0.
You can achieve this in either of following ways :
Run vscode as superuser:
$ sudo code --user-data-dir=~/root
This will open vscode without your previous settings (fresh) with superuser privileges and you can install your extensions.
OR
Follow these steps :
sudo chown -R <user> <path_to_your_vscode_installation_directory>
Hit follwing in terminal
to check the current user on your machine :
whoami
for e.g. john
You can find path of vscode directory using following command :
whereis code
e.g. in my case path is : /usr/share/code
Now run :
sudo chown -R john /usr/share/code
This will run vscode with admin privilege
Now install your extensions
After reset owner back to root
sudo chown -R root /usr/share/code
My simple solution is:
sudo code --verbose --user-data-dir --no-sandbox
(not as root but as sodoer user)
You can press Shift+Cmd+P in visual studio code and type:
shell command
and press "install" in the PATH.
Then in your terminal go to the folder that you want to open and type "code ." It'll open the project in visual studio code as root.
To able to run vs code as superuser:
open code file with a text editor
sudo nano /usr/bin/code
then comment on the following line of codes :
if [ "$(id -u)" = "0" ]; then
for i in "$#"
do
case "$i" in
--user-data-dir | --user-data-dir=* | --file-write )
CAN_LAUNCH_AS_ROOT=1
;;
esac
done
if [ -z $CAN_LAUNCH_AS_ROOT ]; then
echo "You are trying to start Visual Studio Code as a super user which isn't recommended. If this was intended, please specify an alternate user data directory using the \`--user-data-dir\` argument." 1>&2
exit 1
fi
fi
to
#if [ "$(id -u)" = "0" ]; then
# for i in "$#"
# do
# case "$i" in
# --user-data-dir | --user-data-dir=* | --file-write )
# CAN_LAUNCH_AS_ROOT=1
# ;;
# esac
# done
# if [ -z $CAN_LAUNCH_AS_ROOT ]; then
# echo "You are trying to start Visual Studio Code as a super user which isn't recommended. If this was intended, please specify an alternate user data directory using the \`--user-data-dir\` argument." 1>&2
# exit 1
# fi
#fi
here's a step-by-step solution on how to resolve the error "You are trying to start Visual Studio Code as a super user which isn't recommended" when upgrading VS Code in the terminal:
Open a terminal window and navigate to the directory where the VS Code executable is located.
Run the command:code --no-sandbox --user-data-dir=/my/custom/data/dir .
This will start VS Code without the sandbox and use the specified directory for user data.
In my case, in OpenSuse tumbleweed, I performed a couple of extra steps:
I needed to invoke sudo telling it to preserve the environment as vscode (X11 really) needs to know the value of the DISPLAY environment variable.
I wanted to reuse my existing data dir and installed extensions.
sudo -E code --user-data-dir=$HOME/.config/Code --extensions-dir=$HOME/.vscode/extensions
After I am done with my editing / debugging session, I needed to reset the permissions of the data dir and extensions, like so:
sudo chown -R your-user:your-group $HOME/.config/Code $HOME/.vscode/extensions
Where your-user and your-group correspond to your uid/gid which you can obtain from the id command.
I found C# support for SCons (https://bitbucket.org/russel/scons_csharp/overview), but I don't know where to install (copy) the python scripts are copied into.
I installed Scons with brew command, so I have /usr/local/Cellar/scons/2.3.4 directory on my Mac.
What should be the next step to install the C# builders?
Please visit the index of all external SCons Tools at http://www.scons.org/wiki/ToolsIndex . Under the section "Install and usage" you can find a list of search directories for each platform.
Note that, since the C# support is not a core package, it's not installed into your default SCons distribution. Instead, it's treated like a customization (decoration?) of the standard sources...hence the machine/user-specific search paths.
Create a directory ~/.scons/site_scons/site_tools.
cd ~/.scons/site_scons/site_tools
hg clone https://bitbucket.org/russel/scons_csharp
Change one line (460) from csharp.py (~/.scons/site_scons/site_tools/scons_csharp/csharp.py).
env['CSC'] = env.Detect('mcs') or 'csc'
We need this change because the default setting for compiler (gmcs) is outdated.
Create build file: SConstruct.
env = Environment(
tools=['scons_csharp']
)
sources = ['Hello.cs']
prog = env.CLIProgram('myapp', sources)
Execute scons -Q to get:
mcs -nologo -noconfig -out:.../myapp.exe Hello.cs
References
http://www.scons.org/wiki/ToolsIndex
http://www.scons.org/wiki/CsharpBuilder
I have a console application that is available via nuget or on it's own. It gets installed into the tools directory for the NuGet package. The application requires 3 pieces of 'configuration' information.
a database connection string
a folder path
one more configuration option (string)
Currently, I store these configuration values in a text file right next to the exe in a file called settings.js, serialized as json.
When the application first runs, if the file is not present, it creates one with default values.
I keep the settings.js file in this location so the file will get checked into source control.
My question is about maintaining the settings file across versions.
If you Update-Package via nuget, everything works great, except the new version doesn't have any settings i had configured, because there is a new folder created for the new version.
I have written a powershell script to run in init.ps1 to pull the settings from the last version of the package, and seems to work. However this feels kinda dirty and I am wondering if there is a better way to solve this problem when using nuget to deliver my application.
param($installPath, $toolsPath, $package)
Set-Alias hump (Join-Path $toolsPath hump.exe)
$sorted_list = new-object system.collections.SortedList
$parent_path = Join-Path $installPath ".."
foreach($f in Get-ChildItem $parent_path -Filter Humpback* | Foreach {$_.FullName}){
$sorted_list.Add($f,$f)
}
if($sorted_list.Count -gt 1){
$old_path = $sorted_list.Values[$sorted_list.Count - 2]
$new_path = Join-Path $installPath "tools"
$current_settings = Join-Path $new_path "settings.js"
$has_current_settings = Test-Path $current_settings
if($has_current_settings -eq $false){
$old_settings = Join-Path $old_path "tools\settings.js"
Copy-Item $old_settings $new_path
}
}
Also, init.ps1 doesn't appear to run when installing a package using the command line tool (nuget.exe). Is this expected behavior?
Can you access System.Environment.GetFolderPath? I'd just create a folder under ApplicationData special folder, and store the settings there.