UWP AppX Install parameters - c#

I develop client-server UWP app, and I want it to be deployed by sideloading (probably using WinAppDeployCmd or MDM) to the large set of devices by administrator.
But to launch, my application needs to know server IP address, which varies for each customer. I need to pass this setting somehow during deployment by administrator to every device.
Is there a way to set remote application settings? Or pass an XML config file along with appx? Or any other way to add some parameters during installation process?

Unlike e.g. MSI, there's no option to pass along "initial data" with a package for installation. One option is to install the package and then add your 'data' e.g.
Add-AppxPackage foo.appx
appdata = ApplicationDataManager.CreateForPackageFamily(foo_pkg_family)
appdata.LocalSettings.CreateContainer("x").values["y"] = z
Step 1 installs the package, most notably it will register the package for the user. That creates the package's appdata storage resources for the user. You can then use ApplicationDataManager (from a Win32/non-UWP process) to access appdata.
You may find AppData.exe handy. A simple exe using ApplicationDataManager to provide a cmdline interface to AppData. Given this or equivalent you could write a batch file
#ECHO Off
powershell -c Add-AppxPackage foo.appx
appdata.exe SET foopkgfamilyname local\configuration --value=x --type=string --data=y

Related

.NET executables do not work after overwritten with new versions

I faced very strange behaviour - after I overwrite .NET exectables with new versions from network drive it cannot start.
When try to start from Windows Explorer it shows me following error:
[Window Title]
C:\Programs\zzz\clients.net\zzzNet.exe
[Content]
C:\Programs\zzz\clients.net\zzzNet.exe
The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
I tried to execute following commands:
SxsTrace Trace -logfile:SxsTrace.etl
SxStrace Parse -logfile:SxSTrace.etl -outfile:SxSTrace.txt
And got following result:
=================
Begin Activation Context Generation.
Input Parameter:
Flags = 0
ProcessorArchitecture = AMD64
CultureFallBacks = en-US;en;ru-RU;ru
ManifestPath = C:\Programs\zzz\clients.net\zzzNet.exe
AssemblyDirectory = C:\Programs\zzz\clients.net\
Application Config File = C:\Programs\zzz\clients.net\zzzNet.exe.Config
-----------------
INFO: Parsing Application Config File C:\Programs\zzz\clients.net\zzzNet.exe.Config.
INFO: Parsing Manifest File C:\Programs\zzz\clients.net\zzzNet.exe.
INFO: Manifest Definition Identity is (null).
ERROR: Line 0: XML Syntax error.
ERROR: Activation Context generation failed.
End Activation Context Generation.
It is quite simple .NET application (1 exe + 8 dll files). It was built for .NET 3.5 Client Profile.
I not defined any special "manifest" there. Just clicked "New Windows Forms Project" in Visual Studio and developed it.
Also app.config does not contain anything special - only primitive standard settings - appSettings and userSettings sections.
On PC where I developed it all is perfectly works. Problems only began when I copy these binaries to this particular VM and try to start.
Also please note - these executables were not installed in GAC or such, I just copied them into a folder on VM and started. And when it was 1st time all was working fine.
So, the problem pattern is following:
Copy .NET execuatbles to new VM (it is Win 7 x64), run it, all is working fine. Close it.
Build new version of .NET execuatbles on host PC, copy new .NET execuatbles to VM (with files overwriting).
Try to start - got mentioned problem.
After some shaman-style actions (like OS reboot, etc) it begin to work but why that happened at all?!
Why replacing .NET executables with new versions is causing SUCH HUGE PROBLEMS?!
Also the BIG QUESTION - is there any special procedure to replace .NET executables to keep them working? Because it is a new app development, I do not want lost so much time on every new executables installation. :-\
Could you please help? Because it looks completely weird!
Thank you in adance.
PS. I checked all VS projects - all they have PlatformTarget=AnyCPU. Also in run-time I can see ProcessType=MSIL (I show this info in AboutBox for application). So, there is no mix of x86/x64 binaries.
It seems that was related to mapped network drive behavior.
When I copied new files from network drive folder it copied wrong files - a strange random mess of new files and older ones (which were there before I updated them on VM host).
The scenario to make it working:
on VM: delete all files in a folder on network drive
on VM host: copy new files into a folder which is mapped as network drive on VM
on VM: copy files into target folder
on VM: run application - it works now
Weird thing. I remember I have seen something similar with Windows Explorer on Windows 2008 behaviour when copying updated win32 binaries.

How To Set Folder Permissions in Elastic Beanstalk Using YAML File?

I have a C# Web API Elastic Beanstalk app which needs a folder outside the deployment directory that the IUSER and IIS_USERS users can write to. I've created a .config file and put this in the top level .ebextensions folder in my project. The contents are below:
commands:
0_mkdir:
command: mkdir C:\\AppFolder\\
1_set_iuser_permissions:
command: cacls C:\\AppFolder\\ /t /e /g IUser:f IIS_Users:f
However while the folder is created successfully the permissions aren't set. If anyone has any idea what I am doing wrong I would be hugely grateful. Big thanks in advance.
In the end I switched to using Json instead of YAML as, despite my YAML being validated by several online YAML testers, AWS still wouldn't accept it. It always had issues with the parameters passed to icacls. I also changed to a folder within the application App_Data folder as setting permissions on any directory external to the application didn't appear to work. So, my final configuration file is as follows:
{
"container_commands": {
"01": {
"command": "icacls \"C:/inetpub/wwwroot/AppName_deploy/App_Data/AppFolder\" /grant DefaultAppPool:(OI)(CI)F"
}
}
}
Hope this helps someone else out.
It looks like you are using invalid .net accounts (unless these are custom accounts you created). That is part of the reason why your permissions are not being set. They should be IUSR or IIS_IUSRS
Furthermore, container_commands executes after your app/server environment has been setup, but before your deployment has started. There is no other way to set permissions on files/folders within your deployment directory other than using a wpp.targets file within visual studio.
The following SO post is a good read using wpp.targets to solve your issue.
Can Web Deploy's setAcl provider be used on a sub-directory?
Place a file 01_fix_permissions.config inside .ebextensions folder.
contents:
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/49_change_permissions.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
sudo chown -R ec2-user:ec2-user tmp/

TeamCity building with MsBuild and NuGet: "Unable to connect to the remote server"

I have setup my TeamCity to build using MsBuild a project that NuGet packages.
During the build, the following command to install packages is issued, but fails:
..\nuget.exe install "C:\TeamCity\buildAgent\work\811b6866c8757c46\Service\packages.config" -source "https://nuget.org/api/v2/" -RequireConsent -solutionDir "..\ "
Error:
Unable to connect to the remote server
with exit code 1.
Interesting to note is that when I run this exact same command on the cmd prompt (inside the same path), it succeeds without any errors.
This is what I have done so far:
Add a new Build Parameter under environment variables in TeamCity: env.EnableNuGetPackageRestore and set it to 'true'
Add a specific path to the package sources (https://nuget.org/api/v2/) inside the ..nuget\nuget.targets file (as described here)
To provide the additinal paths ways to supply a path:
Modified the nuget.config file inside the .nuget folder (..nuget\nuget.config)
Modified the nuget.config for the SYSTEM account that the build runner is executing under (C:\Windows\SysWOW64\config\systemprofile\AppData\Roaming\NuGet\nuget.Config) (as described here)
What I was thinking is that this has something to do with a roaming profile of the System user (that the build agents runs with) because it all works when build agent runs with my account. But the nuget.config is the same for both profiles, and I'm out of ideas. Maybe the System user doesn't have access to the Internet on WinServer2012R2? Maybe it needs additional permissions? Which ones?
Do you have any ideas of what to try?
The error turned out to be the setting for the ISA server we have on our network (the TMG client). By default this isn't set up for new (local) users and therefore the SYSTEM account didn't have access to the web.
I've set this up for a new local user (non-domain, with password that doesn't expire), added it to Administrators group and now it works just fine.

Firebird client installation

I'm trying to deploy my Application that uses a Firebird v2.5 database to a client machine.
I am trying to use a minimum installation, without the need to run any other installers. From what I gather, all I need to do is copy the "FBClient.dll" to the target application folder (which includes firebird database file). I have tried this and it still reports an error about not being able to find the correct .net data provider.
eg
C:\Program Files (x86)\MyApp\myApp.exe
C:\Program Files (x86)\MyApp\fbDatabase.fdb
C:\Program Files (x86)\MyApp\fbclient.dll
The error produced is:
Failed to find or load the registered .Net Framework Data Provider.
Also have copied, renamed and included fbclient.dll as fbembed.dll
I have also tried to copy a bunch of other files to the app directory, as well as placing fbclient.dll into the c:\, c:\windows, c:\windows\system.
I also tried installing the client installation, with no joy too.
Is there a way, that I can use the firebird database, without manually editing the machine.config files or using the gac and going through the hell that I went through to install firebird on the dev machine? I want an application that a user can install, not requiring that it be installed by a developer.
Please note, the application that I am writing is for a single machine, single user environment, who knows how to double click the install button, with the attention span of a gnat, that if required to do more than double click install and then press GO, will simply get bored and press the cancel, forget it button.
I add the file "FirebirdSql.Data.FirebirdClient.dll" to the application folder and I no longer get the Data provider error, instead I get the following
"Unable to complete network request to host \"DevMachine\"."
at FirebirdSql.Data.Client.Managed.Version10.GdsConnection.Connect()
at FirebirdSql.Data.FirebirdClient.ClientFactory.CreateManagedDatabase(FbConnectionString options)
at FirebirdSql.Data.FirebirdClient.ClientFactory.CreateDatabase(FbConnectionString options)
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.Connect()
I am trying to connect with the following
string file = #"C:\Program Files (x86)\MyApp\Test.FDB;";
FbConnection con = new FbConnection("User=SYSDBA;" + "Password=masterkey;" + "Database=" + file + "DataSource=Dev-VS-W7VM;" + "Port3050;" + "Dialect=3;" + "Charset=ISO8859_1;");
try
{
con.Open();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
I have included FirebirdSql.Data.FirebirdClient in my project and installation folder (..\MyApp)
Thank you in advance.
You have to grap a zip and copy FirebirdSql.Data.FirebirdClient.dll to bin folder.
I wonder how you wrote your application that it works without the file (probably installed .msi) :)
You needed to install .net provider
http://www.firebirdsql.org/en/net-provider/
The database file resides next to your application's exe module. So, you need in local server running or embedded server in order to work with data. For embedded server a minimal set of files is (specifed relatively to an application folder):
\UDF (folder with UDF needed if any)
\Intl (with contents from FB installation)
fbembed.dll
firebird.msg
ib_util.dll
icudt30.dll
icuin30.dll
icuuc30.dll
Microsoft.VC80.CRT.manifest
msvcp80.dll
msvcr80.dll
for a full scale server (i.e. not an embedded) a list of files would be:
\UDF (folder with UDF needed if any)
\Intl (with contents from FB installation)
fbserver.exe or fb_inet_server.exe
fbclient.dll
firebird.msg
ib_util.dll
icudt30.dll
icuin30.dll
icuuc30.dll
Microsoft.VC80.CRT.manifest
msvcp80.dll
msvcr80.dll
security2.fdb
firebird.conf (if non default parameters used)
But then you would need in setting up service record for FB
or start it as an application before your application start.
Installation of the Firebird as a service could be done with
instsvc.exe utility. Appropriate commands:
instsvc install -s -a
instsvc start
Also you should take care of two things:
FileName must be a local file, not in a shared folder from another server.
Appending the firebird server IP before the filename. If you are running your app always in the firebird server, or you are using embeded fbclient.dll, than it should be like
FbConnection con = new FbConnection("User=SYSDBA;" + "Password=masterkey;" + "Database=localhost:" + file + "DataSource=Dev-VS-W7VM;" + "Port3050;" + "Dialect=3;" + "Charset=ISO8859_1;");
Some fbclient.dll version will allow you not to add localhost and still connect on local files, or use \\servername\c:\filename format instead of localhost:c:\filename, but it is deprecated and not supposed to work anymore (and can work depending on windows version).

Enable - SP Feature fails to find the configuration section in the web apps config

I have a site for which i want to activate feature using powershell
When i run the following command :
enable-spfeature FEATURE NAME -url http://URL
it throws an error :value cannot be null parameter name section.
it basically fails to find the configuration section located under the web application configuration.If i create a file with name powershell.exe.config and place it under the
powershell folder ,it works fine but i dont want to touch the system folder.
Is it possible to give powershell a path of config located int some other folder and ask it to use that while activating feature.
I have tried something like this but with no luck
$configpath = "C:\DevTools.exe.config"
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE",$configpath)
enable-spfeature Feature name -url http://url
Why arn't you putting the configuration information in the web application web.config file?
#Lee Activating the feature from powershell expects the configuration to be under the hosting process which is powershell in this case.
The solution to my problem was to load the configuration at run time as shown below and using windows powershell instead of using sharepoint management shell :
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE",$configpath)
add-type -path C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Configuration.dll
Add-PSSnapin Microsoft.Sharepoint.PowerShell
enable-spfeature $FeatureName -url http:\\url

Categories