I'm trying to replace a file in a .appv archive file.
I know you can just rename the file to .zip extract and replace the file.
But when I zip it again and rename it back to .appv the file size is different and i get the following error when opening.
Im trying to change the AppxManifest.xml file or a setting within that without having to open via the UI(cmd, c# or powershell).
Thanks
Open up your sequencer and choose "Modify"
"Update"
Then I am skipping the steps where you upload your .appv file and installer (if you don't need the files from installer, you can always ignore it)
"Continue to modify"
Close the last page and it will automatically jumps to this page
Now, you can open up your package, expand the folder and add files if you want
The best option is to use one of the application packaging tools that supports editing of App-V package. Apart from Advanced Installer that has been already mentioned, take a look at AdminStudio and PACE Suite - both support editing App-V. There may be even more than those two I know.
You cannot zip a package back and expect to work, this is not supported by Microsoft.
Starting with App-V 5.1 the Sequencer from Microsoft can export and import the manifest file from the package, so you can modify it, but from what I know you cannot script this, it must be done from the GUI. The list of powershell cmdlets for the sequencer is quite short.
Also, Advanced Installer can also create and edit App-V packages much easily and faster than the sequencer, but again only from the GUI.
You can also try a free tool, called TweakApp-V, here's an example of you can use it. It has predefined commands to add/delete files and registry.
Related
Background Info:
I needed to convert PDF files to images and have full control over how this is done, and noticed that this functionality does exist in NuGet packages, but only in paid packages. Because I am a cheap bastard I refused to pay for this as I can easily do this in python for free.
I created a way to call a python script from c# that converts the PDF I want to a jpg in the exact way I want, and used this for a while. Now I want to build on this project and thought about creating this into a class library that I can use in multiple projects.
The problem I am now facing is that for this python script to work I need a specific resource, a couple of files in a folder. When I add the existing project (the pdf to img converter) to another project it just adds the DLL, and ignores everything else. The files I need are still in a folder inside the class library.
When I try to access the necessary files the current path is inside the new project, and there those files don't exist.
Directory.GetCurrentDirectory(); tells me that the current path is inside the new project.
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); tells me where the DLL is located, but the files I need aren't there.
I have tried searching for a way to access files inside the class library but I came up with nothing useful.
The question:
Is there a way to access files inside of a project that you are referencing? or is there a way to ensure the files I need are brought over too, instead of just the DLL?
Just for completion, I intend to make this into my own private Nuget package, and Im sure I can get the files I need in the .nupkg, but the same problem will persist, How do I access those files.
If anyone has any experience with this kind of problem, I would be happy to hear from you. Thank you in advance.
I would try to use a c# solution in this case to convert pdf to jpeg.
May be something like this:
Convert pdf to jpeg using a free c# solution
or optimal solution: a nuget package, which you can define as dependency in your nuget package
but there are many other solutions instead a phyton script.
Reason:
If you like to provide a nuget package (even if its company intern) the library
should not have dependencies that are not transparent.
In your case ist the dependency to an available phyton installation in the envirement, where the package will be used.
The software that uses the package must have the rights to execute a phyton script
In additional, you will resolve the issue, that you must be able to store and execute a script, if you use a c# solution
In my console based program I am wanting to use a sound file at the end of it, I was able to get that to work however when I publish the project and try send it to others I can't get it to include the sound file, how would I accomplish this?
There are many potential solutions. One of them could be embedding the sound file as a resource.
I recommend writing an installer. Sooner or later you'll need one anyway. Maybe you have seen one of them before. It's that thing that always asks for administrator permissions and you click on the Next button until everything is installed properly.
I'd like to point you to InnoSetup, which is a free, text based installer. That's great to use with version control systems. I especially like it, because I can modify every necessary detail in my build script: just write a line of text to that file with the version number and it simply works.
It's very simple to learn and there are plenty of examples available online. The documentation is great and complete.
What you need is the [Files] section, something like
[Files]
Source: "MYPROG.EXE"; DestDir: "{app}"
Source: "MYSOUND.WAV"; DestDir: "{app}"
And then you can just access the music from the same directory as your executable.
See also the question "List of InnoSetup pages in order with parameters and screenshot" which gives you an impression of the capabilities of InnoSetup.
Add the WAV file to your project (right-click your project in Solution Explorer, select Add | Existing Item...)
In Solution Explorer go to the properties for the file you added,
and for Build Action select "Embedded Resource".
Add the following code to your console app:
Code:
System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream s = a.GetManifestResourceStream("<assemblyname>.<wavfilename>.wav");
SoundPlayer player = new SoundPlayer(s);
player.PlaySync();
replacing <assemblyname> with the name of your assembly, and <wavfilename> with the name of the WAV file that you added.
For my test code, that line looked like this:
System.IO.Stream s = a.GetManifestResourceStream("ConsoleApp3.tada.wav");
because my assembly name is "ConsoleApp3" and the wav file was called "tada.wav".
Note you will also need to add a using System.Media; to the source code file.
I'm still learning the basics of how VS2010 sees the world. Apparently, you can optionally "include" a file in a project. I'm a bit confused by this: If a file is version-controlled, AND the file is within the project directory, shouldn't it implicitly be "included" in the project? If not, what's the use case where a version-controlled file in the project directory should NOT be included in the project?
=== Addition ===
Based on the answers I've gotten so far, maybe I should rephrased my question: What does it mean for a file to be "included" in a project?
A project needs to know about files in order for compilation and distribution to occur. Just because you have a file that's under source-control, doesn't mean that it will be compiled if the project is unaware of it.
Also, you may want to include files as part of a distribution package. We do this quite often for our web projects that we distribute using web app gallery.
Conversely, you could have documentation or sql scripts that you version control, but do not want them to be part of the project.
EDIT: In answer to your update, what it means for a file to be included in a project is that the file is actually added to the .csproj or .vbproj file and will be used during compilation and/or distribution. VS does differentiate if the file is Content or if it needs to Compile it. This can be seen by clicking on the file in Solution Explorer and looking at the Build Action property.
No, you don't want random files that happen to be in the project directory included in source control.
We do sometimes put documentation (pdfs) or drawings/schematics in the project folder and under version control but you don't need them inside the visual studio project (especially when they are not being distributed because they are for internal use only).
Excluding the file from your project can be useful if the file is related to the project but not necessarily needed in the solution.
Example
If I need some test XML for an application that i'm writing; that is designed to normally be pulling this from a WCF service, it can be useful to keep that file in the directory for a development environment where I use IO to get the XML for testing, but I don't necessarily want it in my solution which is source controlled.
When you exclude a file from a project is no longer compiled or embedded, then when you want to include it again you can do so without having lost your settings.
If you e.g. copy a file (containing a helpful class which want to have in your project) into a folder of your project, then you will see ... nothing. You have to check the option "Show all files" of the solution explorer and the copied file can be seen, but it is still "greyed out". No you can choose the menuitem Include in project and that file will be integrated in your project and a pending change (add) for your source control is added too. Visual Studio doesn't include all files it can find in the project folder automatically to the project - and that is a good feature.
One of my colleagues explained to me a scenario in which a version-controlled file should NOT be part of the project. Here's the idea:
A developer writes some new code.
The code is experimental, and not intended to be part of the normal build.
The easiest way to exclude the file from the build is to NOT include it in the project, but still version-control it.
This way, the file can be shared with other developers, but not break the build.
I have many kinds of xml-files (all with extension .xml) with different root element name and namespace. I want to associate each type with a different application and also make it possible to have different file-icons for each type. Can this be done using C# .NET?
The only way to handle this is in a similar way to that which Visual Studio uses to handle .sln files which is the Visual Studio Version Selector. This application is the one that gets associated with .sln files and handles providing an icon and an eventual process to handle the specific .sln file. Assuming you have Visual Studio installed, take a look in the registry at HKEY_CLASSES_ROOT\VisualStudio.Launcher.sln to see how it's done.
So basically you need to:
Write an executable that can decide what to do with .xml files
Register the process as the one responsible for handling .xml files
Place logic in your executable, or in configuration that your executable consumes, that decides what to do on a per file basis.
For icons, take a look at the subkey ShellEx\IconHandler. You'll see that it points to (on an x64 machine with Visual Studio 2010 installed) HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{9A2B23E4-2A50-48DB-B3C3-F5EA12947CB8} which lists under InprocServer32 a DLL that is responsible for providing icons for files, in this instance C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\VSFileHandler.dll. You'll need to implement a similar DLL that shares the configuration/logic of your launcher process to determine what icon to show on a per file basis.
The usual caveat: Writing shell extensions in managed code has always been a big "no no" because shell extensions get loaded into any process that shows the common file dialogs. This can cause merry chaos as, up until .net 4.0, only one version of the CLR can be loaded into a process, so you have to be very sure before doing this. Given that .net 4.0 supports in-process side by side, this may not be an issue for you.
No. To Windows, an XML file is an XML file. The OS doesn't look inside to see what namespace is associated with it; it's just an XML file.
Windows associates file types with their extension, so again, all XML files are XML files. You can see this for yourself: rename a normal .txt file that contains absolutely no XML, and then refresh the view of it's folder in Explorer. You'll see the icon change from a text file image to an XML file image.
There isn't a way that you can do this without having custom extensions or an intermediary program.
Maybe one option would be to have a custom applicaiton which is assigned to handle XML files. When this is program is spawned it works out what the "type" of the file is using one of the XML tags and spawns the correct process accordingly. It's unlikely, however that you can give different "types" different icons.
I want an Open File Dialog with ****.class*** ,****.jar*** filters.
I want that *.jar files will be treated as folders (pressing OK or double-click should display the jar file content [ *.class] ). This capability is very similar to the TotalCommander archive plugin that let you browse inside archive files in-place (without the need to extract them, etc...)
Any ideas how it could be done? Can I use something that is already implemented?
Thanks,
Guy
To do this with that standard windows explorer and common dialogs you will need to write or find an appropiate Shell namespace extension.
A shell namespace extension is an COM object that allows you to present virtual folders in the explorer shell. So in your case the shell extension will allow the user to navigate the jar file structure as if it where a folder on your machine.
You can write a shell extension with managed code, but at least for versions of the framework prior to 4.0 this was not supported by MS because of potention problems with conflict of loading more than one version of the framework into a process. Now that 4.0 supports side by side loading of framework versions, maybe this is supported.
Here is a link to an article on writting a shell namespace extension
http://msdn.microsoft.com/en-us/magazine/cc188741.aspx
I never tried this, but here is an extension that supports treting 7-zip supported files as a folder. Maybe this will help you at least get started if you need to do this yourself.
http://7zipshell.codeplex.com/
Here's an article that describes the opening of Jars in C#:
http://www.codeproject.com/KB/files/opening_jars_cs.aspx
If you combine that either with Chris answer about writing an extension or you write your own dialog if that's easier, you should be able to do what you want.