Browse Source

Fixed SD2-1642: NotImplementedException when converting project from C# to VB

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5460 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
cd0fbe430d
  1. 8
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/VBNetToCSharpConverter.cs
  2. 6
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/CSharpToVBNetConverter.cs
  3. 13
      src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs
  4. 58
      src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs
  5. 4
      src/Main/Base/Project/Src/Project/MSBuildInternals.cs

8
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/VBNetToCSharpConverter.cs

@ -61,11 +61,11 @@ namespace CSharpBinding
// (we replace existing NoWarn entries because VB and C# error codes don't match) // (we replace existing NoWarn entries because VB and C# error codes don't match)
project.SetProperty("NoWarn", "1591"); project.SetProperty("NoWarn", "1591");
FixProperty(project, "DefineConstants", project.ChangeProperty("DefineConstants",
v => v.Replace(',', ';')); v => v.Replace(',', ';'));
FixProperty(project, "ProjectTypeGuids", project.ChangeProperty("ProjectTypeGuids",
v => v.Replace(ProjectTypeGuids.VBNet, ProjectTypeGuids.CSharp, StringComparison.OrdinalIgnoreCase)); v => v.Replace(ProjectTypeGuids.VBNet, ProjectTypeGuids.CSharp, StringComparison.OrdinalIgnoreCase));
} }
protected override void ConvertAst(CompilationUnit compilationUnit, List<ISpecial> specials, FileProjectItem sourceItem) protected override void ConvertAst(CompilationUnit compilationUnit, List<ISpecial> specials, FileProjectItem sourceItem)

6
src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/CSharpToVBNetConverter.cs

@ -60,9 +60,9 @@ namespace VBNetBinding
{ {
VBNetProject vbProject = (VBNetProject)targetProject; VBNetProject vbProject = (VBNetProject)targetProject;
base.CopyProperties(sourceProject, targetProject); base.CopyProperties(sourceProject, targetProject);
FixProperty(vbProject, "DefineConstants", v => v.Replace(';', ',')); vbProject.ChangeProperty("DefineConstants", v => v.Replace(';', ','));
FixProperty(vbProject, "ProjectTypeGuids", vbProject.ChangeProperty("ProjectTypeGuids",
v => v.Replace(ProjectTypeGuids.CSharp, ProjectTypeGuids.VBNet, StringComparison.OrdinalIgnoreCase)); v => v.Replace(ProjectTypeGuids.CSharp, ProjectTypeGuids.VBNet, StringComparison.OrdinalIgnoreCase));
// determine the StartupObject // determine the StartupObject
startupObject = vbProject.GetEvaluatedProperty("StartupObject"); startupObject = vbProject.GetEvaluatedProperty("StartupObject");

13
src/Main/Base/Project/Src/Project/Converter/LanguageConverter.cs

@ -94,19 +94,6 @@ namespace ICSharpCode.SharpDevelop.Project.Converter
} }
} }
/// <summary>
/// Changes all instances of a property in the <paramref name="project"/> by applying a method to its value.
/// </summary>
protected void FixProperty(MSBuildBasedProject project, string propertyName, Converter<string, string> method)
{
lock (project.SyncRoot) {
throw new NotImplementedException();
/*foreach (MSBuild.BuildProperty p in project.GetAllProperties(propertyName)) {
p.Value = method(p.Value);
}*/
}
}
protected virtual void FixExtensionOfExtraProperties(FileProjectItem item, string sourceExtension, string targetExtension) protected virtual void FixExtensionOfExtraProperties(FileProjectItem item, string sourceExtension, string targetExtension)
{ {
List<KeyValuePair<string, string>> replacements = new List<KeyValuePair<string, string>>(); List<KeyValuePair<string, string>> replacements = new List<KeyValuePair<string, string>>();

58
src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

@ -76,7 +76,7 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary> /// </summary>
public ProjectRootElement MSBuildProjectFile { public ProjectRootElement MSBuildProjectFile {
get { get {
if (projectFile == null) if (projectFile == null)
throw new ObjectDisposedException("MSBuildBasedProject"); throw new ObjectDisposedException("MSBuildBasedProject");
return projectFile; return projectFile;
} }
@ -88,7 +88,7 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary> /// </summary>
public ProjectRootElement MSBuildUserProjectFile { public ProjectRootElement MSBuildUserProjectFile {
get { get {
if (projectFile == null) if (projectFile == null)
throw new ObjectDisposedException("MSBuildBasedProject"); throw new ObjectDisposedException("MSBuildBasedProject");
return userProjectFile; return userProjectFile;
} }
@ -97,8 +97,7 @@ namespace ICSharpCode.SharpDevelop.Project
public override int MinimumSolutionVersion { public override int MinimumSolutionVersion {
get { get {
lock (SyncRoot) { lock (SyncRoot) {
if (string.IsNullOrEmpty(projectFile.ToolsVersion) || projectFile.ToolsVersion == "2.0") if (string.IsNullOrEmpty(projectFile.ToolsVersion) || projectFile.ToolsVersion == "2.0") {
{
return Solution.SolutionVersionVS2005; return Solution.SolutionVersionVS2005;
} else if (projectFile.ToolsVersion == "3.0" || projectFile.ToolsVersion == "3.5") { } else if (projectFile.ToolsVersion == "3.0" || projectFile.ToolsVersion == "3.5") {
return Solution.SolutionVersionVS2008; return Solution.SolutionVersionVS2008;
@ -519,7 +518,7 @@ namespace ICSharpCode.SharpDevelop.Project
static ProjectPropertyElement GetAnyUnevaluatedProperty(ProjectRootElement project, string configuration, string platform, string propertyName) static ProjectPropertyElement GetAnyUnevaluatedProperty(ProjectRootElement project, string configuration, string platform, string propertyName)
{ {
foreach (var g in project.PropertyGroups) { foreach (var g in project.PropertyGroups) {
var property = g.Properties.FirstOrDefault(p => p.Name == propertyName); var property = g.Properties.FirstOrDefault(p => MSBuildInternals.PropertyNameComparer.Equals(p.Name, propertyName));
if (property == null) if (property == null)
continue; continue;
string gConfiguration, gPlatform; string gConfiguration, gPlatform;
@ -535,33 +534,32 @@ namespace ICSharpCode.SharpDevelop.Project
return null; return null;
} }
/*
/// <summary> /// <summary>
/// Get all instances of the specified property. /// Get all instances of the specified property.
/// ///
/// Warning: you need to lock(project.SyncRoot) around calls to GetAllProperties /// Warning: you need to lock(project.SyncRoot) around calls to GetAllUnevaluatedProperties
/// until you no longer need to access the BuildProperty objects! /// until you no longer need to access the ProjectPropertyElement objects!
/// </summary> /// </summary>
public IList<MSBuild.BuildProperty> GetAllProperties(string propertyName) IEnumerable<ProjectPropertyElement> GetAllUnevaluatedProperties()
{ {
List<MSBuild.BuildProperty> l = new List<MSBuild.BuildProperty>(); return projectFile.Properties.Concat(userProjectFile.Properties);
foreach (MSBuild.BuildPropertyGroup g in project.PropertyGroups) { }
if (g.IsImported) continue;
MSBuild.BuildProperty property = MSBuildInternals.GetProperty(g, propertyName); /// <summary>
if (property != null) { /// Changes all instances of a property in the <paramref name="project"/> by applying a method to its unevaluated value.
l.Add(property); ///
} /// The method will be called within a <code>lock (project.SyncRoot)</code> block.
} /// </summary>
foreach (MSBuild.BuildPropertyGroup g in userProject.PropertyGroups) { public void ChangeProperty(string propertyName, Func<string, string> method)
if (g.IsImported) continue; {
MSBuild.BuildProperty property = MSBuildInternals.GetProperty(g, propertyName); lock (this.SyncRoot) {
if (property != null) { foreach (ProjectPropertyElement p in GetAllUnevaluatedProperties()) {
l.Add(property); if (MSBuildInternals.PropertyNameComparer.Equals(p.Name, propertyName)) {
p.Value = method(p.Value);
}
} }
} }
return l;
} }
*/
#endregion #endregion
#region SetProperty #region SetProperty
@ -581,12 +579,12 @@ namespace ICSharpCode.SharpDevelop.Project
PropertyStorageLocations FindExistingPropertyInAllConfigurations(string propertyName) PropertyStorageLocations FindExistingPropertyInAllConfigurations(string propertyName)
{ {
foreach (var g in projectFile.PropertyGroups) { foreach (var g in projectFile.PropertyGroups) {
if (g.Properties.Any(p => p.Name == propertyName)) { if (g.Properties.Any(p => MSBuildInternals.PropertyNameComparer.Equals(p.Name == propertyName))) {
return MSBuildInternals.GetLocationFromCondition(g.Condition); return MSBuildInternals.GetLocationFromCondition(g.Condition);
} }
} }
foreach (var g in userProjectFile.PropertyGroups) { foreach (var g in userProjectFile.PropertyGroups) {
if (g.Properties.Any(p => p.Name == propertyName)) { if (g.Properties.Any(p => MSBuildInternals.PropertyNameComparer.Equals(p.Name == propertyName))) {
return MSBuildInternals.GetLocationFromCondition(g.Condition) return MSBuildInternals.GetLocationFromCondition(g.Condition)
| PropertyStorageLocations.UserFile; | PropertyStorageLocations.UserFile;
} }
@ -824,7 +822,7 @@ namespace ICSharpCode.SharpDevelop.Project
foreach (var propertyGroup in targetProject.PropertyGroups) { foreach (var propertyGroup in targetProject.PropertyGroups) {
if (propertyGroup.Condition == groupCondition) { if (propertyGroup.Condition == groupCondition) {
foreach (var property in propertyGroup.Properties.ToList()) { foreach (var property in propertyGroup.Properties.ToList()) {
if (property.Name == propertyName) { if (MSBuildInternals.PropertyNameComparer.Equals(property.Name, propertyName)) {
property.Value = newValue; property.Value = newValue;
return; return;
} }
@ -857,7 +855,7 @@ namespace ICSharpCode.SharpDevelop.Project
foreach (var propertyGroup in project.PropertyGroups.ToList()) { foreach (var propertyGroup in project.PropertyGroups.ToList()) {
bool propertyRemoved = false; bool propertyRemoved = false;
foreach (var property in propertyGroup.Properties.ToList()) { foreach (var property in propertyGroup.Properties.ToList()) {
if (property.Name == propertyName) { if (MSBuildInternals.PropertyNameComparer.Equals(property.Name, propertyName)) {
propertyGroup.RemoveChild(property); propertyGroup.RemoveChild(property);
propertyRemoved = true; propertyRemoved = true;
} }
@ -1288,11 +1286,11 @@ namespace ICSharpCode.SharpDevelop.Project
{ {
foreach (var g in project.PropertyGroups) { foreach (var g in project.PropertyGroups) {
if (string.IsNullOrEmpty(g.Condition)) { if (string.IsNullOrEmpty(g.Condition)) {
var prop = g.Properties.FirstOrDefault(p => p.Name == "Configuration"); var prop = g.Properties.FirstOrDefault(p => MSBuildInternals.PropertyNameComparer.Equals(p.Name, "Configuration"));
if (prop != null && !string.IsNullOrEmpty(prop.Value)) { if (prop != null && !string.IsNullOrEmpty(prop.Value)) {
configurationNames.Add(prop.Value); configurationNames.Add(prop.Value);
} }
prop = g.Properties.FirstOrDefault(p => p.Name == "Platform"); prop = g.Properties.FirstOrDefault(p => MSBuildInternals.PropertyNameComparer.Equals(p.Name, "Platform"));
if (prop != null && !string.IsNullOrEmpty(prop.Value)) { if (prop != null && !string.IsNullOrEmpty(prop.Value)) {
platformNames.Add(prop.Value); platformNames.Add(prop.Value);
} }

4
src/Main/Base/Project/Src/Project/MSBuildInternals.cs

@ -31,6 +31,10 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary> /// </summary>
public readonly static object SolutionProjectCollectionLock = new object(); public readonly static object SolutionProjectCollectionLock = new object();
// TODO: I think MSBuild actually uses OrdinalIgnoreCase. SharpDevelop 3.x just used string.operator ==, so I'm keeping
// that setting until all code is ported to use PropertyNameComparer and we've verified what MSBuild is actually using.
public readonly static StringComparer PropertyNameComparer = StringComparer.Ordinal;
internal static void UnloadProject(MSBuild.Evaluation.ProjectCollection projectCollection, MSBuild.Evaluation.Project project) internal static void UnloadProject(MSBuild.Evaluation.ProjectCollection projectCollection, MSBuild.Evaluation.Project project)
{ {
lock (SolutionProjectCollectionLock) { lock (SolutionProjectCollectionLock) {

Loading…
Cancel
Save