Sometimes, when coding a web application in visual studio, you may want to have the project start in an InPrivate or Incognito window. Browsers, such as Chrome, Edge, Firefox, and others, have a special way to open them that is clean as in no cookies or history or logins and it isn’t tied to your normal browser session. This is called Private browsing. They each brand it a little differently, with Edge being InPrivate and Chrome using Incognito, but they are all private browsing.
Visual Studio can easily be configured to open the browser in private browsing.
Configure Visual Studio to Launch the Browser in Private Mode
Open Visual Studio
Locate your Asp.Net Application and open it
or
Create a new Asp.Net Project (you can throw away this project afterward)
Once the project is open, locate the Debug Target icon, which is a green triangle that looks like a start icon:
Click the drop-down arrow just to the right of it.
Select Browse with:
In the Browse With screen, click Add.
Enter one or more of these values: (I entered both)
Often, a solution may have both Unit Tests and Integration Tests. Unit Tests should be highly specific, and should be testing one class object. Integration Test could be vastly more complex and could use Selenium, or require a real database server, etc. Even if a solution doesn’t have Integration Tests, it may have slow Unit Tests. For example, I have a test that takes about 2 minutes to run because it is testing that when creating 10 million random strings, the character distribution is pretty equal.
I don’t want to either slow Unit Tests or Integration Tests to run every single time I build on my local dev box. I do have an automated build system and builds kick off on check-in. At that time, these slow tests will run every time. But locally, it is just an unnecessary delay.
Usually I am writing in a specific project and that project has specific tests and I can easily choose to only run tests in my current project. But what if I am updating a library that many projects use. I want to know quickly if anything is broke, so I need to run most of the tests in the entire solution.
Visual Studio allows for tests to be tagged with a TestCategoryAttribute.
You can mark different tests with different names: [TestCategory(“Slow”)], [TestCategory(“Integration”)], [TestCategory(“Performance”)], [TestCategory(“Selenium”)]
Example:
[TestMethod]
[TestCategory("Slow")]
public void TestDistributionInTenMillionCharacters()
{
// some code here
}
All other tests are left without a test category. Now, if you want to run all tests that aren’t slow, you can do this in Visual Studio Test Explorer by grouping tests using the “Traits” selection option.
Once you have marked all tests with an appropriate TestCategoryAttribute, you can sort by Trait. Now it is simple to click-to-highlight the No Traits group and click Run | Selected Tests.
Update 12/14/2016:
You should be aware that when doing a custom clean, that in Visual Studio choosing Clean and then Build in two steps is not the same as doing Rebuild.
Clean <-- Cleans all projects
Build <-- Builds all projects
Rebuild <-- For each project, clean the project, then rebuild the project.
So Rebuild is a huge problem and here is why: Since my code is pretty decoupled, my plugins don't reference the project hosting the plugins. So there is not dependency to guarantee the plugin-hosting project cleans and builds first. So when running reubild, a plugin might clean and build and then copy its files to the plugin directory. This could happen before the plugin-hosting project cleans and builds. So you can imagine that once the plugin-hosting project cleans and builds, the newly copied plugin files are cleaned. To fix this, I had to manually add a dependency or just not use Rebuild.
Update: Projects using NuGet for Source with Add as Link. If you have a project using this please comment and let me know.
https://github.com/rhyous/SimpleArgs
https://github.com/rhyous/EasyXml
https://github.com/rhyous/EasyCsv
https://github.com/rhyous/SimplePluginLoader
https://github.com/rhyous/StringLibrary
So I have a project on GitHub called SimpleArgs. This project makes command line arguments easy in a C# project. However, one of the requirements is to have an option to use the SimpleArgs dll or to have a single file executable. Yes, everything in one single exe, so referencing a dll is not an option.
So I created two separate NuGet packages from this project:
SimpleArgs – This NuGet package uses a dll
SimpleArgs.Sources – This NuGet package adds source
I use SimpleArgs.Sources the most. I quickly realized that NuGet for source does not scale. I have a Solution with four different projects where each project is a single file executable. The result was many copies of the SimpleArgs code.
MySolution
/Packages &lt;-- Copy of SimpleArgs source
/SingleExe1 &lt;-- Copy of SimpleArgs source
/SingleExe2 &lt;-- Copy of SimpleArgs source
/SingleExe3 &lt;-- Copy of SimpleArgs source
/SingleExe4 &lt;-- Copy of SimpleArgs source
That is 5 copies of the SimpleArgs source. Now at first, this doesn’t seem to be a big problem, in fact, it seems little more than an annoyance. One of the first changes I made, was to exclude the duplicate copies of source from Git. This helped but not enough. There are still problems that occur with multiple copies of source. For example, I ran into a bug with SimpleArgs. I fixed it, and then some time later I ran into the same bug with another project in the same solution. Oh, yeah. I only fixed the bug in one copy of the SimpleArgs source.
I decided the best solution was to reference the source using Add as link. Add as link is the ability to include a file into your Visual Studio project but without making a copy of the file in your project.
I quickly changed the projects so the source was included not as copies but using the Add As Link capability. I manually did this. Then I finally pushed my changes to SimpleArgs Git repository and released a new version of the SimpleArgs.Sources NuGet package. That basically wiped out my manual work to Add As Link.
I needed the NuGet packages include the source using Add As Link for me.
How to create NuGet package using Add As Source
Well, to my dismay, NuGet didn’t have this feature built in. At first I was exciting about the possibility that this feature would be added as part of NuGet 3.3 and the contentFiles feature, but unfortunately, this feature is for Universal Windows projects, and not for Console Application, Windows Forms, or WPF projects.
However, NuGet does run a PowerShell script on install and another on uninstall, called install.psi and uninstall.ps1. It took some work, I even gave up once, but eventually I found the right library and the documentation for it to help me solve this.
Step 1 – Create a NuGet Packager Project in Visual Studio
Open Visual Studio and go to File | New Project.
Note: Steps 2 thru 7 installs the NuGet Packager project from online. If you have already done this, then you probably can create your project without these steps. 🙂
At the bottom of the list on the right, click Online to expand it.
Note: For some reason, Visual Studio hung for about ten to twenty seconds when I clicked this.
In the search bar on the top right, enter NuGet.
Select NuGet Packager.
Give your project a Name.
Note: Mine is named SimpleArgs.Sources.
Give your solution a Name.
Click Ok.
See steps 2 – 7 in this image: When you click OK, the template will install. It will prompt you a few times but once installed, your project will be created.Note: From now on, you can find the NuGet Packager project in Installed | Templates | Visual C# | NuGet.
Step 2 – Fill out the Package.nuspec file metadata
The package.nusepc is an Xml file. It is created as follows:
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;package &gt;
&lt;metadata&gt;
&lt;id&gt;SimpleArgs.Sources&lt;/id&gt;
&lt;version&gt;1.0.0&lt;/version&gt;
&lt;title&gt;SimpleArgs.Sources&lt;/title&gt;
&lt;authors&gt;Jjbarneck&lt;/authors&gt;
&lt;owners&gt;&lt;/owners&gt;
&lt;description&gt;A long description of the package. This shows up in the right pane of the Add Package Dialog as well as in the Package Manager Console when listing packages using the Get-Package command.&lt;/description&gt;
&lt;releaseNotes&gt;&lt;/releaseNotes&gt;
&lt;summary&gt;A short description of the package. If specified, this shows up in the middle pane of the Add Package Dialog. If not specified, a truncated version of the description is used instead.&lt;/summary&gt;
&lt;language&gt;en-US&lt;/language&gt;
&lt;projectUrl&gt;https://nuget.org/packages/SimpleArgs.Sources&lt;/projectUrl&gt;
&lt;iconUrl&gt;https://nuget.org/Content/Images/packageDefaultIcon-50x50.png&lt;/iconUrl&gt;
&lt;requireLicenseAcceptance&gt;false&lt;/requireLicenseAcceptance&gt;
&lt;licenseUrl&gt;http://opensource.org/licenses/Apache-2.0&lt;/licenseUrl&gt;
&lt;copyright&gt;Copyright 2016&lt;/copyright&gt;
&lt;dependencies&gt;
&lt;group targetFramework=&quot;net40&quot;&gt;
&lt;dependency id=&quot;log4net&quot; version=&quot;1.2.10&quot; /&gt;
&lt;/group&gt;
&lt;/dependencies&gt;
&lt;references&gt;&lt;/references&gt;
&lt;tags&gt;&lt;/tags&gt;
&lt;/metadata&gt;
&lt;files&gt;
&lt;file src=&quot;lib\&quot; target=&quot;lib&quot; /&gt;
&lt;file src=&quot;tools\&quot; target=&quot;tools&quot; /&gt;
&lt;file src=&quot;content\&quot; target=&quot;content&quot; /&gt;
&lt;/files&gt;
&lt;/package&gt;
Package.nuspec Changes
I can’t go over every possible nuspec setting. That is in the Nuspec Reference. However, I’ll give you the basics of what I changed.
id – Set this to your package name. If you named your project correctly, this is already named correctly. I’ll leave the above unchanged.
version – This is your version. If this is your first release, 1.0.0 is perfect. I am changing mine to 1.1.0 as my last version was 1.0.9.
title – Often the same as the id, but not always. I’ll leave mine as is.
authors – This is me. I want something other than the Visual Studio username. I changed this to Jared Barneck (Rhyous)
owners – This is me or my business. I’ll change this to Rhyous Publishing LLC
description – Long description. This is defined in the Xml. Change it to describe your NuGet package.
releaseNotes – I just put a link to the release notes in my GitHub repo: https://github.com/rhyous/SimpleArgs/blob/master/ReleaseNotes.txt
summary – Short description. This is also defined in the xml. This is usually shorter than the description.
language – This is the 5 digit language IETF language tag. I left mine at en-US.
projectUrl – I changed this to my GitHub location: https://github.com/rhyous/SimpleArgs
iconUrl – I changed this to the icon file in my GitHub source. Unlike the release notes and the license file, I used the raw GitHub link for the image: https://raw.githubusercontent.com/rhyous/SimpleArgs/master/Docs/Images/SimpleArgs.Logo.png
requireLicenseAcceptance – I left this as false. Only set this to true if your license requires an agreement.
licenseUrl – I set this to the license file in my GitHub repository:
https://github.com/rhyous/SimpleArgs/blob/master/Fork%20and%20Contribute%20License.txt
copyright – I set this to Copyright Rhyous Publishing LLC
dependencies – This project has no dependencies, so I deleted this entire section.
references – I deleted this tag. Source NuGet packages probably won’t have any references.
tags – Since my project is for command line arguments, I set my tags to: args, arguments
files – This was preconfigured, however, I replaced the libs\ with src\ because I didn’t have any libs but I have source.
In Visual Studio, in Solution Explorer, you should see that there are already four folders provided for you. See the image to your right. ———–>
content – This is what is going to be copied to your project. Since we don’t want all our source copied, we aren’t going to put our source here.
Note: I would delete this folder, but it turns out, I have one source file that isn’t shared. ArgsHandler.cs will be customized in each project, which makes sense because each project will have different args and handle args differently. ArgsHandler.cs will go here.
libs – I have no libs. I can delete this folder and the associated xml for it in the nuspec.
src – Stuff I put here isn’t copied to my projects. I am going to put all my shared source in this folder.
tools – this has the PowerShell scripts: init.ps1, install.ps1, and uninstall.ps1
Now that we understand our folder structure, let’s get to work.
In Visual Studio’s Solution Explorer, create a folder called App_Packages under the src directory.
Note: I was going to use App_Sources but NuGet recommends that we follow what other community members follow and others have already started putting source files under App_Packages, so I am following that community convention. Also, this is important for the PowerShell scripts, as this convention plays a part in them. If you don’t follow this convention, you will have to edit the and uninstall.psi PowerShell scripts, which I’ll be providing later.
In Visual Studio’s Solution Explorer, create a Folder with the project name and version. In my case, the folder name is this: SimpleArgs.Sources.1.1.0.
Note: Again, this was by community convention. Others were doing this. You don’t have to follow this exactly, again, If you don’t follow this convention, you will have to edit the install.ps1 and uninstall.psi PowerShell scripts, which I’ll be providing later.
In Windows Explorer, not in Visual Studio, put your source under the project name and version directory.
Note: In Visual Studio’s Solution Explorer, I only have these two directories: App_Packages/SimpleArgs.Sources.1.1.0.
Note: In Windows Explorer, My directory structure ended up as follows:
Note: There is a good reason that I don’t include these in the NuGet Packager Visual Studio project, which I will explain later.
Step 4 – Add Source Files
As mentioned earlier, the ArgsHandler.cs file isn’t shared. Each project does need its own copy of this file. So we need to add it so that it supports Source Code Transformations.
In Visual Studio’s Solution Explorer, copy any source files into the Content directory. You may put them in sub directories if you wish. I created an Arguments folder.
Add .pp to the end of any source files.
Change the namespace to $rootnamespace$ in any source files. You may also add a sub namespace to the end of $rootnamespace$ as I did.
using SimpleArgs;
using System;
using System.Collections.Generic;
namespace $rootnamespace$.Arguments
{
// Add this line of code to Main() in Program.cs
//
// ArgsManager.Instance.Start(new ArgsHandler(), args);
//
/// &lt;summary&gt;
/// A class that implements IArgumentsHandler where command line
/// arguments are defined.
/// &lt;/summary&gt;
public sealed class ArgsHandler : ArgsHandlerBase
{
// content snipped see full file here: https://github.com/rhyous/SimpleArgs/blob/master/NuGet/SimpleArgs.NuGet/content/Arguments/ArgsHandler.cs.pp
}
}
Step 5 – Add As Link in NuGet using PowerShell scripts
There are three PowerShell scripts.
init.ps1
install.ps1
uninstall.ps1
We are only going to modify install.ps1 and uninstall.ps1.
Note: The following are written to be very generic and have been tested in various Visual Studio projects, which means some common bugs are already fixed, such as not failing on creation of App_Packages just because it is already there.
Update install.ps1.
Note: For the latest versions of install1.ps1 and uninstall.ps1, go to the tools directory on my GitHub repo.
# Runs every time a package is uninstalled
param($installPath, $toolsPath, $package, $project)
# $installPath is the path to the folder where the package is installed.
# $toolsPath is the path to the tools directory in the folder where the package is installed.
# $package is a reference to the package object.
# $project is a reference to the project the package was installed to.
# Variables
$src = &quot;src&quot;
$packageName = [System.IO.Path]::GetFileName($installPath)
#logging
write-host &quot;project: &quot; $project.FullName
write-host &quot;installPath: &quot; $installPath
write-host &quot;toolsPath: &quot; $toolsPath
write-host &quot;package: &quot; $package
write-host &quot;project: &quot; $project
$srcPath = [System.IO.Path]::Combine($installPath, $src)
write-host &quot;srcPath: &quot; $srcPath
$solutionDir = [System.IO.Path]::GetDirectoryName($dte.Solution.FullName)
$projectDir = [System.IO.Path]::GetDirectoryName($project.FullName)
write-host &quot;solutionDir: &quot; $solutionDir
write-host &quot;projectDir: &quot; $projectDir
$areSameDir = $solutionDir -eq $projectDir
write-host &quot;areSameDir: &quot; $areSameDir
function AddLinkedFiles($path, $addLocation, $canLink)
{
write-host &quot;path: &quot; $path
write-host &quot;addLocation: &quot; $addLocation.FullName
write-host &quot;canLink: &quot; $canLink
foreach ($item in Get-ChildItem $path)
{
write-host &quot;item: &quot; $item $item.FullName
if (Test-Path $item.FullName -PathType Container)
{
if ( $canLink) {
$addFolder = $project.ProjectItems|Where-Object {$_.FullName -eq $item.FullName}
if (!$addFolder) {
$addFolder = $addLocation.ProjectItems.AddFolder($item)
}
write-host &quot;addFolder: &quot; $addFolder.FullName
AddLinkedFiles $item.FullName $addFolder $canLink
} else
{
AddLinkedFiles $item.FullName $addLocation $canLink
}
}
else
{
write-host &quot;Adding &quot; $item.FullName &quot; to &quot; $addLocation.FullName
$addLocation.ProjectItems.AddFromFile($item.FullName)
}
}
}
write-host &quot;Calling AddLinkedFiles&quot;
AddLinkedFiles $srcPath $project (!$areSameDir)
Update uninstall.ps1.
# Runs every time a package is uninstalled
param($installPath, $toolsPath, $package, $project)
# $installPath is the path to the folder where the package is installed.
# $toolsPath is the path to the tools directory in the folder where the package is installed.
# $package is a reference to the package object.
# $project is a reference to the project the package was installed to.
# Variables
$packages = &quot;Packages&quot;
$app_packages = &quot;App_Packages&quot;
$src = &quot;src&quot;
$packageName = [System.IO.Path]::GetFileName($installPath)
#logging
write-host &quot;project: &quot; $project.FullName
write-host &quot;installPath: &quot; $installPath
write-host &quot;toolsPath: &quot; $toolsPath
write-host &quot;package: &quot; $package
write-host &quot;project: &quot; $project
$srcPath = [System.IO.Path]::Combine($installPath, $src)
write-host &quot;srcPath: &quot; $srcPath
$solutionDir = [System.IO.Path]::GetDirectoryName($dte.Solution.FullName)
$projectDir = [System.IO.Path]::GetDirectoryName($project.FullName)
write-host &quot;solutionDir: &quot; $solutionDir
write-host &quot;projectDir: &quot; $projectDir
$areSameDir = $solutionDir -eq $projectDir
write-host &quot;areSameDir: &quot; $areSameDir
if ($areSameDir) {
$packagesItem = $project.ProjectItems|Where-Object {$_.Name -eq $packages}
write-host &quot;packageFolder: &quot; $packagesItem.Name
$item = $packagesItem.ProjectItems|Where-Object {$_.Name -eq [System.IO.Path]::GetFileName($installPath)}
write-host &quot;item: &quot; $item.Name
$item.Remove()
if ($packagesItem.ProjectItems.Count -eq 0) {
$packagesItem.Remove()
}
} else {
$app_packagesItem = $project.ProjectItems|Where-Object {$_.Name -eq $app_packages}
write-host &quot;app_packagesItem: &quot; $app_packagesItem.Name
$app_packagesFolder = [System.IO.Path]::Combine($srcPath,$app_packages)
foreach ($subDir in (Get-ChildItem $app_packagesFolder)) {
$item = $app_packagesItem.ProjectItems|Where-Object {$_.Name -eq $subDir.Name}
write-host &quot;item: &quot; $item.Name
if ($item) {
$item.Delete()
}
}
if ($app_packagesItem.ProjectItems.Count -eq 0 -and (Get-ChildItem ([System.IO.Path]::Combine($projectDir, $app_packages))).Count -eq 0) {
$app_packagesItem.Delete()
}
}
Step 6 – Build the solution and NuGet package
The NuGet Packager project template is pretty awesome. When you use it, it builds the NuGet package for you on build. Also, if you build in release mode, it will try to upload the NuGet package to the public NuGet Package Gallary.
In Visual Studio, make sure the Solution Configuration is set to Debug.
Choose to Build | Build Solution.
In your project directory, you should have a NuGet package built. Mine is called SimpleArgs.Sources.1.1.1.nupkg.
Stay Tuned
Stay tuned for NuGet for Source Using Add As Link (Part 2 – Testing & Deploying)
There may be times when you need to share source between projects but you can’t reference a dll. This would happen if you are writing multiple single file executables and you wanted to share source between them. By definition, a single file executable doesn’t reference a dll or it would not be a single file.
You can still share source using Visual Studio’s Add As Link feature.
To use Add As Link in Visual Studio, follow these steps.
Right-click on your project in Solution Explorer and choose Add | Existing Item.
Next navigate to your shared file and click to highlight the file.
Next click the drop down arrow next to Add and choose Add As Link.
Verify that the file was added as a link. You can tell because it has a different icon to distinguish it from other source files.
Verify that the Build Action is set to Compile. It should be as this is the default Build Action for a .cs file.
Microsoft is to acquire Xamarin. Read the article here. Xamarin is far and away the best tool for writing cross-platform mobile apps, but their business model greatly slowed the company’s customer acquisition.
A new mobile developer could easily install Eclipse for free and develop a mobile app without zero cost. The minimum Xamarin fee cost $25 a month but it did not work with Visual Studio. The minimum Xamarin version that worked with Visual Studio cost $1000 a month.
Better business models existed. I long recommended that Xamarin be completely free to for developers to download and use, but the compiled code should have been time-bombed for one day. Of course, with IL editors such time-bombing could be removed, but doing so would not be easy. This model would have allowed them to gather all the indie developers who had an idea and quickly get their application to work on iOS, Android, and Windows. Then at release time, charging a fee to publish the app would have been more palatable. In the long run it would have resulted in more customers and users. It would have skyrocketed the number of xamarin developers. I believe Xamarin would have ended up making far more money by charging less to way more users. But Xamarin disagreed.
Microsoft sees the need to make Xamarin the go to language from cross-platform apps. The flaky and hacked together html5 stack is the only other option for true cross-platform development. Microsoft and Visual Studio has a marge larger user base than Xamarin. If Microsoft’s intention to maintain Xamarin’s model, they would be making a huge mistake.
Microsoft should immediately add Xamarin to the Visual Studio Enterprise subscribers. Enterprise is the top-level and should get everything. There will be some loss of revenue as some Xamarin customers are also Enterprise subscribers, but that loss in negligible and would probably be made up by higher renewal rates and less downgrades. However, if Miocrosoft were to add all of Xamarin also to their Visual Studio Professional subscribers, Xamarin might lose a huge portion of revenue, as most Xamarin customers are also Visual Studio Subscribers. If they want to keep this revenue, then they could easily add a mobile subscription level for mobile only developers and then a professional plus mobile subscription level entices current professional developers to upgrade.
However, what if Microsoft doesn’t care about Xamarin’s revenue at all. What if what they care about is getting mobile developers to primarily use Visual Studio. What if they give Xamarin in its entirety away free in Community Edition so everyone at any Visual Studio level would have it. And what if they open source it?
How many more users would flock to Visual Studio Community Edition? This could be the catalyst to dethrone JavaScript. To bring thousands of users to the Microsoft development ecosystem that also includes Azure. What types of increases in their cloud users could this bring? Perhaps the Xamarin acquistion is not intended to continue to make its own revenue. Perhaps the acquisition is nothing more than a feature add to their existing technology stack.
Were I Microsoft’s CEO, Satya Nadella, I would go the Community Edition route. But I’m not him and I do not know what he is going to do. We are left to wait and see.
So I have a bunch of files in a NuGet package that need the File Properties set as follows:
Build Action
Content
Copy to Output Directory
Copy if newer
Custom Tool
Custom Tool Namespace
I am using the NuGet package Project that you can find in the Online projects.
I was able to set these values in a NuGet package as follows using the Install.ps1 PowerShell script. I found this out thanks to Workabyte’s answer on StackOverflow
I would just set something to what I wanted it to be, then I would look at its value.
Here is my full Install.ps1
# Runs every time a package is installed in a project
param($installPath, $toolsPath, $package, $project)
# $installPath is the path to the folder where the package is installed.
# $toolsPath is the path to the tools directory in the folder where the package is installed.
# $package is a reference to the package object.
# $project is a reference to the project the package was installed to.
function SetFilePropertiesRecursively
{
$folderKind = "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}";
foreach ($subItem in $args[0].ProjectItems)
{
$path = $args[1]
if ($subItem.Kind -eq $folderKind)
{
SetFilePropertiesRecursively $subItem ("{0}{1}{2}" -f $path, $args[0].Name, "\")
}
else
{
Write-Host -NoNewLine ("{0}{1}{2}" -f $path, $args[0].Name, "\")
SetFileProperties $subItem 2 2 ""
}
}
}
function SetFileProperties
{
param([__ComObject]$item, [int]$buildAction, [int]$copyTo, [string]$customTool)
Write-Host $item.Name
Write-Host " Setting Build Action to Content"
$item.Properties.Item("BuildAction").Value = $buildAction
Write-Host " Setting Copy To Output Directory to Copy if newer"
$item.Properties.Item("CopyToOutputDirectory").Value = $copyTo
Write-Host " Setting Custom Tool to blank"
$item.Properties.Item("CustomTool").Value = $customTool
}
SetFilePropertiesRecursively $project.ProjectItems.Item("Globalization")
SetFilePropertiesRecursively $project.ProjectItems.Item("Styles")
SetFileProperties $project.ProjectItems.Item("App.xaml") 4 0 "MSBuild:Compile"
Many have asked for an MSVCR100.dll download. Turns out that Visual Studio has a redistributable folder that contains these dlls. So I zipped it up and I am redistributing it.
This MSVCR110.dll is the Microsoft Visual C++ Redistributable dll that is needed for projects built with Visual Studio 2011. The dll letters spell this out.
MS = Microsoft
V = Visual
C = C++
R = Redistributable
If you create a C++ project in Visual Studio 2011, this file is probably needed.
MSVCR110D.dll
The MSVCR110D.dll is almost the same file only the D at the end stands for Debug. This file has debugging enabled.
Why the error?
Ok, so recently I switched to Visual Studio 2011. I had a C++ application that worked perfectly in Visual Studio 2008. Once I compiled it with Visual Studio 2011 and ran it on a clean 2008 server (fully patched but otherwise clean), it failed to run with the following error.
TestWin32.exe – System Error
The program can’t start because MSVCR110.dll is missing from your computer. Try reinstalling the program to fix this problem.
Here is the screen shot:
The same things happens with the debug version of the file, only it is a the debug version of the same DLL as noted by the fact that the DLL name ends with D.
Autorun – System Error
The program can’t start because MSVCR110.dll is missing from your computer. Try reinstalling the program to fix this problem.
The screen shot is identical except for the D in the dll name.
I create a new project in Visual Studio 2011 using the project type of C++ Win32 Project and without making a single change to the default project, I built the file and tested it on my clean machine and the same issue occurred.
So obviously that is not acceptable. It seems like this should just not happen by default, but unfortunately it does.
Solution
It was actually really easy to resolve for my one project.
Here is what I did.
You can solve this any of the following ways:
Statically link to the dll files so they are compiled into my executable instead of referenced as separate dll files.
Included the dll in the same directory as the exe (I actually didn’t try this but I assume it would work).
Forced everyone to install the VC++ Runtime Redistributable before running the app.
The first option seems the most stable and robust and easiest for a single executable. So that is the one I am going to use.
The second option doesn’t really make sense to me and I would probably never do it. Maybe if I had dozens of executable files that all required the same DLL and I didn’t have an installer, and I wanted to conserve size, which probably wouldn’t happen for me since I am pretty good at creating a quick installer. Though you might be in this a situation.
The third option would make sense if I was planning on running my executable after an install. During the install I could include the VC++ Runtime Redistributable and all would be fine.
Statically Linking the DLLs
Make sure you resolve it for both Release and Debug. The steps are slightly different.
Release
In Visual Studio, I went to the project Properties.
I changed my Configuration to Release.
I went under Configuration Properties | C/C++ | Code Generation
Look at the Runtime Library setting. It is set to this: Multi-threaded DLL (/MD)
Change it to this: Multi-threaded (/MT)
Rebuild.
Debug
Almost exactly the same as release.
In Visual Studio, I went to the project Properties.
I changed my Configuration to Debug.
I went under Configuration Properties | C/C++ | Code Generation
Look at the Runtime Library setting. It is set to this: Multi-threaded Debug DLL (/MDd)
Change it to this: Multi-threaded Debug (/MTd)
Rebuild the debug
It might be a good idea for me to figure out how to change the project so when I create a new project of this type, those settings are the default.
Found a quality development blog recently that had a post on a topic I have been interested in but haven’t got around to working on. The topic is publishing a project using Visual Studio.
As C# developers, many of us would prefer to write Android Apps in C# as well. Novell had promised us MonoDroid, but we were quite concerned as to whether MonoDroid would ever be released when Novell was dismantled.
However, Xamarin spawned from the ashes like a phoenix to restore the viability of MonoDroid, restoring our hopes to writing in C# for the Android platform.
Though I am hopeful that MonoDroid will become popular allowing C# to be a commonly used language for Android devices, there is still some question as to whether Xamarin and its MonoDroid product will survive.
Xamarin is a new company and needs to survive first. Its business is to sell MonoDroid, which is not open source, but is a proprietary product. Unfortunately, MonoDroid may cost too much, preventing adoption among app developers. Xamarin requires a customer base and a continual adoption rate if it is going to survive. If the company folds, what is going to happen to the library and the apps that use it?
Is Development with MonoDroid Free? Yes and No!
Yes and no.
Yes because anybody can use and develop with MonoDroid at no cost. It isn’t until you need to publish an app to the app store that you need to buy a license. You can use the MonoDroid trial for as long as you want. Here is a quote from the trial website. [2]
The evaluation version of Mono for Android does not expire, but enables development and testing against the Android Emulator only.
No, because you need to buy a license once either of the following become true:
You need to test your code directly on a real device and not just an emulated device
You are ready to publish an app to the app store
So what is the cost of MonoDroid? Depends on if you buy Professional, Enterprise, or Enterprise Priority. On the Xamarin store, the following table can be found. To see it you have to add MonoDroid to your cart and then click the “Show product comparison” link. [1]
Professional
Enterprise
Enterprise Priority
Deploy to your devices
Publish to app stores
Enterprise distribution
Priority support queue
Guaranteed response time
License expiration
Never
Never
Never
Update subscription
1 Year
1 Year
1 Year
License usage
Original User
Seat
Seat
Price (USD)
$399
$999
$2,499
These costs are very low for business or enterprise customers who have C# developers and want to write Android apps. The cost of training a C# developer to develop apps for Android in Java may be far greater than training them to develop apps for Android using C# and buying a MonoDroid license.
Is MonoDroid easy to set up?
Update
MonoDroid is not down to a one-click installer.
Here is the old method of Installing without the One-click Installer
MonoDroid is simple to set up. Xamarin has some simple steps that can be found on their web site. They have MonoDroid installation instructions for installing MonoDroid for use with any of three environments.
Visual Studio (Important! Visual Studio Express is not supported)
These are very easy steps to complete, and I won’t repeat the steps here, but once you complete them, you are ready to start writing Android apps in C#.
Once you feel you have everything installed, click the following link to continue reading.
Ok, lets say you want to have a Grid where each item is a row of data in a Grid. The left most column should expand or shrink, and yes the text should wrap when it shrinks.
Not so easy…but it can be done if you use the right tools.
Use a DockPanel not a Grid
Make the left most column the last one added
<Window x:Class="ListBoxWithWrap.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="242"
d:DesignWidth="388"
>
<Grid>
<DockPanel Name="MainGrid" HorizontalAlignment="Stretch">
<!-- These four blocks will have other content eventually, but only need to be 45 wide -->
<TextBlock Text="X" Grid.Column="1" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<TextBlock Text="X" Grid.Column="2" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<TextBlock Text="X" Grid.Column="3" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<TextBlock Text="X" Grid.Column="4" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<!-- This is the TextBlock that needs to wrap its content (and
change the height of the row (so the full content is still
visible) to whatever the available space is, but should not
make overall ListView wider than the parent's width. -->
<TextBlock Text="A very long string that should wrap when the window is small." Padding="20,6,6,6" TextWrapping="Wrap" DockPanel.Dock="Right"/>
</DockPanel>
</Grid>
</Window>
You will see that this works as you desire.
Now put this in a ListView’s Template and set it to use Binding.
<Window x:Class="ListBoxWithWrap.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="242"
d:DesignWidth="388"
SizeToContent="WidthAndHeight">
<Grid>
<ListView Name="lvWrap" ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel Name="MainGrid" HorizontalAlignment="Stretch">
<!-- These four blocks will have other content eventually, but only need to be 45 wide -->
<TextBlock Text="X" Grid.Column="1" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<TextBlock Text="X" Grid.Column="2" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<TextBlock Text="X" Grid.Column="3" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<TextBlock Text="X" Grid.Column="4" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<!-- This is the TextBlock that needs to wrap its content (and
change the height of the row (so the full content is still
visible) to whatever the available space is, but should not
make overall ListView wider than the parent's width. -->
<TextBlock Text="{Binding Content}" Padding="20,6,6,6" TextWrapping="Wrap" DockPanel.Dock="Right"/>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Window>
Now give it some data to bind to.
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
namespace ListBoxWithWrap
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<SomeItem> list = new List<SomeItem>();
list.Add(new SomeItem() { Content = "Some very long string with so many words there should be some wrapping going on to prevent a line of text that is too long" });
list.Add(new SomeItem() { Content = "Some very long string with so many words there should be some wrapping going on to prevent a line of text that is too long" });
list.Add(new SomeItem() { Content = "Some very long string with so many words there should be some wrapping going on to prevent a line of text that is too long" });
list.Add(new SomeItem() { Content = "Some very long string with so many words there should be some wrapping going on to prevent a line of text that is too long" });
list.Add(new SomeItem() { Content = "Some very long string with so many words there should be some wrapping going on to prevent a line of text that is too long" });
lvWrap.DataContext = list;
}
public class SomeItem
{
public string Content { get; set; }
}
}
}
The shrink with text wrapping no longer works once inside of the ListView. So that tells you that something to do with the ListView is breaking the feature you want.
Here is how you fix this:
1. Open your project in Expression Blend. (If you don’t have Expression Blend, maybe just look at my code below and copy it)
2. Right-Click on the ListView in the Object and Timeline tab and choose Edit Template | Edit a Copy.
4. Now look at what is surrounding the ItemPresenter. Yes, you see the ScrollViewer, which is your problem. Delete it.
5. Build you project.
Success! Now your feature to both expand or shrink with text wrapping is back.
Here is the final XAML.
<Window x:Class="ListBoxWithWrap.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="242"
d:DesignWidth="388"
SizeToContent="WidthAndHeight">
<Window.Resources>
<SolidColorBrush x:Key="ListBorder" Color="#828790"/>
<Style x:Key="ListViewStyle1" TargetType="{x:Type ListView}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListView}">
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
</Trigger>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<ListView Name="lvWrap" ItemsSource="{Binding}" Style="{DynamicResource ListViewStyle1}">
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel Name="MainGrid" HorizontalAlignment="Stretch">
<!-- These four blocks will have other content eventually, but only need to be 45 wide -->
<TextBlock Text="X" Grid.Column="1" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<TextBlock Text="X" Grid.Column="2" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<TextBlock Text="X" Grid.Column="3" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<TextBlock Text="X" Grid.Column="4" HorizontalAlignment="Center" Width="45" DockPanel.Dock="Right"/>
<!-- This is the TextBlock that needs to wrap its content (and
change the height of the row (so the full content is still
visible) to whatever the available space is, but should not
make overall ListView wider than the parent's width. -->
<TextBlock Text="{Binding Content}" Padding="20,6,6,6" TextWrapping="Wrap" DockPanel.Dock="Right"/>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Window>
You should now have a little bit more understanding of the ListView template and how to manipulate it, which should translate to other objects in WPF as well.