IVsBuildPropertyStorage SetItemAttribute fails in WPF projects in VS11 Beta
-
Saturday, April 28, 2012 2:21 AM
We have code which will get and set attributes on project items using IVsBuildPropertyStorage GetItemAttribute and SetItemAttribute. We call this code from a custom MSBuild task. This has been working fine in VS2010.
In VS11 Beta we're finding that the SetItemAttribute code fails for items in WPF projects. In all other project types pertinent to us - web application projects, class libraries, and WinForms - no error occurs.
If the WPF project is a VB.NET project a prompt window pops up which says:
"The command you are attempting cannot be completed because the file 'myproject.vbproj' that must be modified cannot be changed. If the file is under source control, you may want to check it out; if the file is read-only on disk, you may want to change its attributes."
The file is not read only, and not under source control. The prompt window has only an OK button, and when then window closes our code appears to complete without error, although the attribute is never set.
In C# projects, instead of seeing the prompt window, VS11 crashes. Using WinDbg we see that the top of the stack trace is:
28ef0b0 59b5b771 csproj!CVsModalState::CVsModalState+0x24
028ef0fc 59b5b8b6 csproj!VspMessageBox+0xd1
028ef11c 59b0317a csproj!VspDisplayString1+0x32
028ef16c 59b03912 csproj!CLangHierarchy::QueryEditProjectFile+0xe3
028ef184 75d0586c csproj!CLangHierarchy::SetItemAttribute+0x3cSo, first, why does this fail in WPF projects only? And second, is there some switch to turn off this check?
Here's our code:
public static bool SetCustomAttribute(ProjectItem projectItem, String attributeName, String attributeValue) {
var storageInfo = GetVsBuildPropertyStorageInfo(projectItem);
if (storageInfo != null) {
String currentValue;
storageInfo.Item1.GetItemAttribute(storageInfo.Item2, attributeName, out currentValue);
if (!attributeValue.Equals(currentValue)) {
storageInfo.Item1.SetItemAttribute(storageInfo.Item2, attributeName, attributeValue);
}
return true;
} else {
return false;
}
}private static Tuple<IVsBuildPropertyStorage, uint> GetVsBuildPropertyStorageInfo(ProjectItem projectItem) {
IVsHierarchy hierarchy = GetVsHierarchy(projectItem.ContainingProject);
IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage;
if (buildPropertyStorage != null) {
uint itemId;
string fullPath = (String)projectItem.Properties.Item("FullPath").Value;
hierarchy.ParseCanonicalName(fullPath, out itemId);
return new Tuple<IVsBuildPropertyStorage, uint>(buildPropertyStorage, itemId);
} else {
return null;
}
}
All Replies
-
Tuesday, May 01, 2012 5:55 AMModerator
Hi Kim,
Please try the following steps.
- In Solution Explorer, select the referenced file.
- On the File menu, choose Check Out.
If this issue remains, please upload your project to Skydrive or other networked disk, and paste its link.
We will try our best to help solve this issue.
Thank you for your understanding!
Lucy Liu [MSFT]
MSDN Community Support | Feedback to us
-
Tuesday, May 01, 2012 4:57 PM
As I stated above, the file, which is the project file, is not under source control.
It's going to be a bit difficult to provide a repro solution since a custom build task is doing the SetItemAttribute call but I will get one together later this week. I think, though, that I will open this as a Connect bug and attach the repro there.
-
Friday, May 04, 2012 6:59 AMModerator
Hi Kim,
Do you have any update about this issue?
If yes, please feel free to let us know.
Thank you for your understanding!
Lucy Liu [MSFT]
MSDN Community Support | Feedback to us
-
Friday, May 04, 2012 9:01 PM
I posted the Connect bug with repro solution here - http://connect.microsoft.com/VisualStudio/feedback/details/740667/.
- Marked As Answer by lucy-liuModerator Monday, May 07, 2012 8:37 AM

