Visual Studio For Mac Show Hidden Files

From @jeffallen on November 24, 2015 18:17 Maybe I just don't know how to use the file chooser in MacOS, but I thought I'd use my nifty new vscode install to edit my.bashprofile and add the code alias proposed in the install docs. When using a remote connection, Visual Studio builds C Linux projects on the remote machine. It doesn't matter if it's a physical machine, a VM in the cloud, or WSL. To build the project, Visual Studio copies the source code to your remote Linux computer. Then, the code gets compiled based on Visual Studio settings.

  1. Visual Studio For Mac Show Hidden Files And Folders
  2. Visual Studio For Mac Show Hidden Files Download
  3. Visual Studio Code Show Hidden Files Mac
  4. Visual Studio For Mac Show Hidden Files Command
  5. Visual Studio For Mac Show Hidden Files In Finder
-->

Git is a distributed version control system that allows teams to work on the same documents simultaneously. This means there is a single server that contains all the files, but whenever a repository is checked out from this central source, the entire repository is cloned locally to your machine.

There are many remote hosts that allow you to work with Git for version control, however the most common host is GitHub. The following example uses a GitHub host, but you can use any Git host for version control in Visual Studio for Mac.

If you wish to use GitHub, make sure that you have an account created and configured before following the steps in this article.

Creating a remote repo on GitHub

The following example uses a GitHub host, but you can use any Git host for version control in Visual Studio for Mac.

To set up a Git repository, execute the following steps:

  1. Create a new Git repo at github.com:

  2. Set Repo Name, description, and privacy. Do not initialize Repo. Set .gitignore and license to None:

  3. The next page gives you an option to display and copy either the HTTPS or SSH address to the repo you have created:

    You'll need the HTTPS address to point Visual Studio for Mac to this repo.

Publishing an existing project

If you have an existing project that is not already in version control, use the following steps to set it up in Git:

Tip

Use a .gitignore file to control which folders and files are tracked and published with Git. You may want to exclude build directories, binaries, or generated files. Learn more in the GitHub docs on ignoring files.

  1. Select the Solution name from the Solution Window in Visual Studio for Mac.

  2. In the Menu bar, select Version Control > Publish in Version Control to display the Clone Repository dialog:

    If this menu item appears greyed out in the menu, make sure you have selected the Solution name.

  3. Choose the Select from Registered tab and press the Add button:

  4. Enter the name of the repository as you would like it to display locally, and paste in the URL from step #3. Your Repository Configuration dialog should look similar to the following. Press OK:

    It is also possible to use SSH to connect to Git.

  5. To attempt to publish the app to Git, select the repository, and ensure that both Module Name and Message text fields are completed:

  6. Click Okay, and then Publish from the alert dialog.

  7. In the Git Credentials window, enter your GitHub username and password.

Note

If your account has two-factor authentication (2FA) enabled, you will need to create an Access Token, which is used in place of a password. If you have not created an access token, follow the steps in the Git Access Token documentation.

  1. Enter the username and Personal Access Token, and press Okay:

  2. After a few seconds, the Solution should be published with its initial commit. Confirm it has been published by browsing the Version Control menu item, which should now be populated with many options:

  3. Once you start to make additional changes, first use the Version Control > Review and Commit menu to open status view. After you've selected and committed changes, select Push to push the changes to the remote repository. This will allow all appropriate users to view it on github.com:

Publishing a new project

Visual Studio For Mac Show Hidden Files And Folders

The new project dialog can be used to create a new project with a local git repository. To enable it, select the Use git for version control checkbox, as illustrated in the following screenshot. This will initialize your repo and add an optional .gitignore file:

Follow the steps below to push your new local repository to a new GitHub repository:

Note

If you have not already created a GitHub repository, refer to the Creating a remote repo on GitHub section.

  1. Create your first commit by going to Version Control > Review and Commit in the Menu Bar.

  2. In the Status tab, choose Commit in the top left.

  3. Write a commit message, for example 'First Commit', then click on Commit:

  4. Next, in the Menu Bar go to Version Control > Manage Branches and Remotes.

  5. Go to the Remote Sources tab, then click Add.

  6. In the Remote Source window, add the details of your previously created GitHub repository and click OK:

  7. Close the Git Repository Configuration window, then in the Menu Bar go to Version Control > Push Changes.

  8. In the Push to Repository window click on the Push Changes button:

  9. When prompted, enter your GitHub username and password.

Note

If your account has two-factor authentication (2FA) enabled, you will need to create an Access Token, which is used in place of a password. If you have not created an access token, follow the steps in the Git Access Token documentation.

Visual Studio for Mac will now push the changes to your remote GitHub repository:

Clone an existing repository

It's likely that you'll have to work with a GitHub repo that exists only on the remote, not on your local machine. Visual Studio for Mac allows you to clone this repo quickly. Follow the steps below to clone it to your machine:

  1. In the Menu bar, select Version Control > Clone Repository:

  2. This displays the Connect with Url tab:

  3. On the GitHub page of the remote repository, press the Clone or Download button and copy the URL provided:

  4. Replace all the text in the URL entry field in the Connect with Url tab. This will populate most other fields in this tab for you, as illustrated in the image in step #2.

  5. Enter the directory that you want to clone the repo into and press Clone.

Note

You may experience issues if the repo is over 4 GB in size.

Troubleshooting

If you have issues with initializing your project with an empty remote repository, you can try the following steps:

  1. Go to your solution folder.
  2. Press Command + Shift + . to show the hidden files and folders.
  3. If there's a .git folder, delete it.
  4. If there's a gitignore file, delete it.
  5. Press Command + Shift + . to hide the files and folders.
  6. Open your solution in VS for Mac.
  7. On the solution Window, select your solution node.
  8. Browse to the Version Control menu and choose Publish in Version Control.
  9. Follow the steps of the above tutorial starting from the step 6.

See also

Files-->

You can use Xamarin.iOS and the System.IO classes in the .NET Base Class Library (BCL) to access the iOS file system. The File class lets you create, delete, and read files, and the Directory class allows you to create, delete, or enumerate thecontents of directories. You can also use Stream subclasses, whichcan provide a greater degree of control over file operations (such ascompression or position search within a file).

iOS imposes some restrictions on what an application can do with the filesystem to preserve the security of an application’s data, and to protect usersfrom malignant apps. These restrictions are part of the Application Sandbox – a set of rules that limits an application’s access to files,preferences, network resources, hardware, etc. An application is limited toreading and writing files within its home directory (installed location); itcannot access another application’s files.

iOS also has some file system-specific features: certain directories requirespecial treatment with respect to backups and upgrades, and applications canalso share files with each other and the Files app (since iOS 11), and via iTunes.

This article discusses the features and restrictions of the iOS file system, and includes a sample application that demonstrates how to use Xamarin.iOS to execute some simple file system operations:

General file access

Xamarin.iOS allows you to use the .NET System.IO classes for filesystem operations on iOS.

The following code snippets illustrate some common file operations. You’llfind them all below in the SampleCode.cs file, in the sample application forthis article.

Hidden

Working with directories

This code enumerates the subdirectories in the current directory (specifiedby the './' parameter), which is the location of your application executable.Your output will be a list of all the files and folders that are deployed withyour application (displayed in the console window while you are debugging).

Reading files

To read a text file, you only need a single line of code. This example willdisplay the contents of a text file in the Application Output window.

XML serialization

Although working with the complete System.Xml namespace isbeyond the scope of this article, you can easily deserialize an XML documentfrom the file system by using a StreamReader like this code snippet:

For more information, see the documentation for System.Xml and serialization. See the Xamarin.iOS documentation on the linker – often you will need to add the [Preserve] attribute to classes you intend to serialize.

Creating files and directories

This sample shows how to use the Environment class to access the Documents folder where we can create files and directories.

Creating a directory is a similar process:

For more information see the System.IO API reference.

Serializing JSON

Json.NET is a high-performance JSON framework that works with Xamarin.iOS and is available on NuGet. Add the NuGet package to your application project, using Add NuGet in Visual Studio for Mac:

Next, add a class to act as the data model for serialization/deserialization (in this case Account.cs):

Finally, create an instance of the Account class, serialize it to json data and write it to a file:

For more information about working with json data in a .NET application, see Json.NET's documentation.

Special considerations

Despite the similarities between Xamarin.iOS and .NET file operations, iOS andXamarin.iOS differ from .NET in some important ways.

Making project files accessible at runtime

By default, if you add a file to your project, it won’t be included in thefinal assembly, and therefore won’t be available to your application. In orderto include a file in the assembly, you must mark it with a special build action,called Content.

To mark a file for inclusion, right-click on the file(s) and choose Build Action > Content in Visual Studio for Mac. You can also changethe Build Action in the file’s Propertiessheet.

Case sensitivity

It’s important to understand that the iOS file system is case-sensitive. Case-sensitivity means that your file and directory names must match exactly – README.txt and readme.txt would be considered different filenames.

This could be confusing for .NET developers who are more familiar with theWindows file system, which is case insensitiveFiles,FILES, and files would all refer to the same directory.

Warning

The iOS Simulator is NOT case-sensitive.If your filename casing differs between the file itself and the referencesto it in code, your code might still work in the simulator but it willfail on a real device. This is one of the reasons why it’s important to deployand test on an actual device early and often during iOS development.

Path separator

iOS uses the forward slash ‘/’as the path separator (which is differentfrom Windows, which uses the backslash ‘’).

Because of this confusing difference, it’s good practice to use the System.IO.Path.Combine method, which adjusts for the currentplatform, rather than hardcode a particular path separator. This is a simplestep that makes your code more portable to other platforms.

Application sandbox

Your application’s access to the file system (and other resources such asthe network and hardware features) is limited for security reasons. Thisrestriction is known as the Application Sandbox. In terms of the filesystem, your application is limited to creating and deleting files anddirectories in its home directory.

The home directory is a unique location in the file system where yourapplication and all its data are stored. You cannot choose (or change) thelocation of the home directory for your application; however iOS and Xamarin.iOSprovide properties and methods to manage the files and directories inside.

The application bundle

The Application Bundle is the folder that contains your application.It is distinguished from other folders by having the .app suffix added to thedirectory name. Your application bundle contains your executable file and allthe content (files, images, etc.) necessary for your project.

When you browse to your application bundle in Mac OS, it appears with adifferent icon than you see in other directories (and the .app suffix ishidden); however, it’s just a regular directory that the operating system isdisplaying differently.

To view the application bundle for the sample code, right-click on theproject in Visual Studio for Mac and select Reveal in Finder. Thennavigate to the bin/ directory where you should find an applicationicon (similar to the screenshot below).

Right-click on this icon and choose Show Package Contents tobrowse the contents of the Application Bundle directory. The contents appearjust like the contents of a regular directory, as shown here:

The application bundle is what’s installed on the simulator or on yourdevice during testing, and ultimately it is what’s submitted to Apple forinclusion in the App Store.

Application directories

When your application is installed on a device, the operating system createsa home directory for your application, and creates anumber of directories within the application root directory that are availablefor use. Since iOS 8, the user-accessible directories are NOT located within the application root, so you can't derive the paths for the application bundle from the user directories, or vice versa.

These directories, how to determine their path, and their purposes are listed below:

DirectoryDescription
[ApplicationName].app/In iOS 7 and earlier, this is the ApplicationBundle directory where your application executable is stored. The directory structure that you create in your app exists in this directory (for example, images and other file types that you’ve marked as Resources in your Visual Studio for Mac project).
If you need to access the content files inside your Application Bundle, the path to this directory is available via the NSBundle.MainBundle.BundlePath property.
Documents/Use this directory to store user documents and application data files.
The contents of this directory can be made available to the user through iTunes file sharing (although this is disabled by default). Add a UIFileSharingEnabled Boolean key to the Info.plist file to allow users to access these files.
Even if an application doesn’t immediately enable file sharing, you should avoid placing files that should be hidden from your users in this directory (such as database files, unless you intend to share them). As long as sensitive files remain hidden, these files will not be exposed (and potentially moved, modified, or deleted by iTunes) if file sharing is enabled in a future version.
You can use the Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments) method to get the path to the Documents directory for your application.
The contents of this directory are backed up by iTunes.
Library/The Library directory is a good place to store files that are not created directly by the user, such as databases or other application-generated files. The contents of this directory are never exposed to the user via iTunes.
You can create your own subdirectories in Library; however, there are already some system-created directories here that you should be aware of, including Preferences and Caches.
The contents of this directory (except for the Caches subdirectory) are backed up by iTunes. Custom directories that you create in Library will be backed up.
Library/Preferences/Application-specific preference files are stored in this directory. Do not create these files directly. Instead, use the NSUserDefaults class.
The contents of this directory are backed up by iTunes.
Library/Caches/The Caches directory is a good place to store data files that can help your application run, but that can be easily re-created. The application should create and delete these files as needed and be able to re-create these files if necessary. iOS 5 may also delete these files (under low storage situations), however it will not do so while the application is running.
The contents of this directory are NOT backed up by iTunes, which means they will not be present if the user restores a device, and they may not be present after an updated version of your application is installed.
For instance, in case your application can't connect to the network, you might use the Caches directory to store data or files to provide a good offline experience. The application can save and retrieve this data quickly while waiting for network responses, but it doesn’t need to be backed up and can easily be recovered or re-created after a restore or version update.
tmp/Applications can store temporary files that are only needed for a short period in this directory. To conserve space, files should be deleted when they are no longer required. The operating system may also delete files from this directory when an application is not running.
The contents of this directory are NOT backed up by iTunes.
For example, the tmp directory might be used to store temporary files that are downloaded for display to the user (such as Twitter avatars or email attachments), but that could be deleted once they've been viewed (and downloaded again if they are required in the future).

This screenshot shows the directory structure in a Finder window:

Accessing other directories programmatically

The earlier directory and file examples accessed the Documentsdirectory. To write to another directory, you must construct a path using the'..' syntax as shown here:

Creating a directory is similar:

Paths to the Caches and tmp directories can beconstructed like this:

Sharing with the Files app

iOS 11 introduced the Files app - a file browser for iOS that allows the user to see and interact with their files in iCloud and also stored by any application that supports it. To allow the user to directly access files in your app, create a new boolean key in the Info.plist file LSSupportsOpeningDocumentsInPlace and set it to true, as here:

The app's Documents directory will now be available for browsing in the Files app. In the Files app, navigate to On My iPhone and each app with shared files will be visible. The screenshots below show what the FileSystem sample app looks like:

Sharing files with the user through iTunes

Users can access the files in your application’s Documents directory by editing Info.plist andcreating an Application that supports iTunes sharing (UIFileSharingEnabled) entry in the Source view, as shown here:

These files can be accessed in iTunes when the device is connected and theuser chooses the Apps tab. For example, the following screenshotshows the files in selected app sharedvia iTunes:

Users can only access the top-level items in this directory via iTunes. Theycannot see the contents of any subdirectories (although they can copy them totheir computer or delete them). For example, with GoodReader, PDF and EPUB filescan be shared with the application so that users can read them on their iOSdevices.

Users who modify the contents of their Documents folder can cause problems ifthey’re not careful. Your application should take this into consideration andbe resilient to destructive updates of the Documents folder.

The sample code for this article creates both a file and a folder in theDocuments folder (in SampleCode.cs) and enables file sharing in the Info.plistfile. This screenshot shows how these appear in iTunes:

Refer to the Working with Images article for information about how to set icons for the applicationand for any custom document types you create.

If the UIFileSharingEnabled key is false or not present, thenfile sharing is, by default, disabled, and users will not be able to interactwith your Documents directory.

Backup and restore

When a device is backed up by iTunes, all the directories created in yourapplication’s home directory will be saved except the following directories:

  • [ApplicationName].app – Don't write to this directory, since it’s signed and so must remain unchanged after installation. It may contain resources that you access from your code, but they do not require backup since they would be restored by re-downloading the app.
  • Library/Caches – The cache directory is intended for working files that do not need to be backed up.
  • tmp – This directory is used for temporary files that are created and deleted when no longer needed, or for files that iOS deletes when it needs space.

Backing up a large amount of data can take a long time. If you decide youneed to back up any particular document or data, your application should use eitheruse the Documents and Library folders. For transient data or files thatcan be easily retrieved from the network, use either the Caches or the tmpdirectory.

Note

iOS will ‘clean’ the filesystem when a device runs critically low on disk space.This process will remove all files from the Library/Caches and tmp folder of applications that are not currently running.

Complying with iOS 5 iCloud backup restrictions

Note

Although this policy was first introduced with iOS 5 (which seems like a long time ago)the guidance is still relevant to apps today.

Apple introduced iCloud Backup functionality with iOS 5. When iCloudBackup is enabled, all the files in your application’s home directory(excluding directories that are not normally backed up, e.g., the app bundle, Caches, and tmp) are backed-up to iCloud servers. This feature provides the user with a complete backup in case their device is lost, stolen, or damaged.

Because iCloud only provides 5 Gb of free space to each user and toavoid unnecessarily using bandwidth, Apple expects applications to only backupessential user-generated data. To comply with the iOS Data Storage Guidelines,you should limit the amount of data that gets backed up by adhering to thefollowing items:

Visual Studio For Mac Show Hidden Files Download

Visual Studio For Mac Show Hidden Files
  • Only store user-generated data, or data that cannot otherwise be re-created, in the Documents directory (which is backed-up).
  • Store any other data that can easily be re-created or re-downloaded in Library/Caches or tmp (which is not backed-up, and could be ‘cleaned’).
  • If you have files that might be appropriate for the Library/Caches or tmp folder but you do not want to be ‘cleaned’ out, store them elsewhere (such as Library/YourData) and apply the ‘do not back up’ attribute to prevent the files from using up iCloud Backup bandwidth and storage space. This data still uses up space on the device, so you should manage it carefully and delete it when possible.

The ‘do not back up’ attribute is set using the NSFileManager class. Ensure your class is using Foundation and call SetSkipBackupAttribute like this:

Visual Studio Code Show Hidden Files Mac

When SetSkipBackupAttribute is true the file willnot be backed-up, regardless of the directory it is stored in (even the Documents directory). You can query the attribute using the GetSkipBackupAttribute method, and you can reset it by calling the SetSkipBackupAttribute method with false, likethis:

Sharing data between iOS apps and app extensions

Since App Extensions run as part of a host application (as opposed to their containing app), the sharing of data isn't automatic included so extra work is required. App Groups are the mechanism iOS uses to allow different apps to share data. If the applications have been properly configured with the correct entitlements and provisioning, they can access a shared directory outside of their normal iOS sandbox.

Configure an App Group

The shared location is configured using an App Group,which is configured in the Certificates, Identifiers & Profiles section oniOS Dev Center. This valuemust also be referenced in each project's Entitlements.plist.

For information on creating and configuring an App Group, refer to the App Group Capabilities guide.

Files

The iOS app and the extension can also share files using a common file path (given they have been properly configured with the correct entitlements and provisioning):

Important

If the Group Path returned is null, check the configuration of the entitlements and the provisioning profile and make sure that they are correct.

Application version updates

When a new version of your application is downloaded, iOS creates a new homedirectory and stores the new Application Bundle in it. iOS then moves thefollowing folders from the previous version of your Application Bundle to yournew home directory:

Visual Studio For Mac Show Hidden Files Command

  • Documents
  • Library

Other directories may also be copied across and put under your new homedirectory, but they’re not guaranteed to be copied, so your application shouldnot rely on this system behavior.

Summary

This article showed that file system operations with Xamarin.iOS are similar to any other .NET application. It also introduced the Application Sandboxand examined the security implications that it causes. Next, it explored theconcept of an Application Bundle. Finally, it enumerated the specializeddirectories available to your application and explained their roles duringapplication upgrades and backups.

Visual Studio For Mac Show Hidden Files In Finder

Related links