Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
By throwing an exception with a usefull error message, that would unblock the user.
  • Loading branch information
Yishai Galatzer committed Oct 12, 2015
1 parent 0d432a5 commit 06eb0f1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void Save(string configFileFullPath, XDocument document)
memoryStream.Seek(0, SeekOrigin.Begin);

// MSBuildNuGetProjectSystem.AddFile() can't handle full path if the app.config
// file does not exist in the project yet. This happens when NuGet first creates
// file does not exist in the project yet. This happens when NuGet first creates
// app.config in the project directory. In this case, only the file name is passed.
var path = configFileFullPath;
var defaultConfigFile = Path.Combine(
Expand All @@ -225,11 +225,11 @@ private static ILookup<AssemblyBinding, XElement> GetAssemblyBindings(XDocument

// We're going to need to know which element is associated with what binding for removal
var assemblyElementPairs = from dependentAssemblyElement in assemblyBindingElements
select new
{
Binding = AssemblyBinding.Parse(dependentAssemblyElement),
Element = dependentAssemblyElement
};
select new
{
Binding = AssemblyBinding.Parse(dependentAssemblyElement),
Element = dependentAssemblyElement
};

// Return a mapping from binding to element
return assemblyElementPairs.ToLookup(p => p.Binding, p => p.Element);
Expand All @@ -243,11 +243,22 @@ private static IEnumerable<XElement> GetAssemblyBindingElements(XElement runtime

private XDocument GetConfiguration(string configFileFullPath)
{
return ProjectManagement.XmlUtility.GetOrCreateDocument(
"configuration",
Path.GetDirectoryName(configFileFullPath),
Path.GetFileName(configFileFullPath),
MSBuildNuGetProjectSystem.NuGetProjectContext);
try
{
return ProjectManagement.XmlUtility.GetOrCreateDocument(
"configuration",
Path.GetDirectoryName(configFileFullPath),
Path.GetFileName(configFileFullPath),
MSBuildNuGetProjectSystem.NuGetProjectContext);
}
catch (Exception ex)
{
var errorMessage = string.Format(Strings.Error_WhileLoadingConfigForBindingRedirects,
configFileFullPath,
ex.Message);

throw new InvalidOperationException(errorMessage, ex);
}
}

private static void UpdateBindingRedirectElement(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/NuGet.Clients/PackageManagement.VisualStudio/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,7 @@
<data name="SolutionIsNotSaved" xml:space="preserve">
<value>Solution is not saved. Please save your solution before managing NuGet packages.</value>
</data>
<data name="Error_WhileLoadingConfigForBindingRedirects" xml:space="preserve">
<value>Failed to load '{0}', while updating binding redirects. {1}</value>
</data>
</root>

0 comments on commit 06eb0f1

Please sign in to comment.