先日公開した Hatena.Helper 1.3 は NuGet 1.2 でパッケージングを行ったのですが、WebMatrix でインストールしようとすると以下のようなエラーが発生します。
どうやら schemaVersion という属性がスキーマに定義されていないので検証時にエラーが発生しているようです。そして schemaVersion 属性は NuGet 1.2 でパッケージングされた時に追加されるようになったみたいですね。
参考までに Hatena.Helper 1.2 と 1.3 の nuspec を出しておきます。
Hatena.Helper 1.2 の nuspec
<?xml version="1.0"?> <package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <id>Hatena.Helper</id> <version>1.2</version> <title>Hatena.Helper</title> <authors>shiba-yan</authors> <owners>shiba-yan</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>The Hatena Web Services (Bookmark, Haiku, Profile, Star) Helper for WebMatrix.</description> <language>en-US</language> <tags>ASPNETWEBPAGES</tags> </metadata> </package>
Hatena.Helper 1.3 の nuspec
<?xml version="1.0" encoding="utf-8"?> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata schemaVersion="2"> <id>Hatena.Helper</id> <version>1.3</version> <title>Hatena.Helper</title> <authors>shiba-yan</authors> <owners>shiba-yan</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>The Hatena Web Services (Auth, Bookmark, Haiku, Profile, Star) Helper for WebMatrix.</description> <language>en-US</language> <tags>ASPNETWEBPAGES</tags> </metadata> </package>
NuGet 1.2 でパッケージングした nuspec には schemaVersion="2" という属性が追加されていました。WebMatrix というか ASP.NET Web Pages が内蔵している NuGet バージョンが古いのが原因のようです。
折角なので NuGet 最新版のソースコードを読んでみました。nuspec ファイルの処理を行っているのは NuGet.Manifest クラスになります。
// Get the metadata node and look for the schemaVersion attribute XElement metadata = GetMetadataElement(document); if (metadata != null) { // Yank this attribute since we don't want to have to put it in our xsd XAttribute schemaVersionAttribute = metadata.Attribute(SchemaVersionAttributeName); if (schemaVersionAttribute != null) { schemaVersionAttribute.Remove(); }
はい、見事に SchemaVersionAttributeName を削除するようになっていました。最新版ではこのような仕組みになっていたので、スキーマの変更なしでもエラーが発生していなかったわけです。
恐らく ASP.NET Web Pages が更新されれば修正されると思うのですが、ASP.NET MVC を見ても分かるようにこまめにアップデートされる気がしないのでどうなるのでしょう…?
追記
中の人から Twitter で返事をいただきました。
@chack411 @shibayan We made a small change to nuget.exe. If you repack now it should only make a 1.2 if you use newer features.
— David Fowler (@davidfowl) 2011, 4月 4
私は NuGet 1.2 が出たその日に更新して使っていたのですが、その後にもう一度アップデートされていたようです。コマンドラインから
NuGet.exe update
と打ち込んで NuGet.exe を更新してからパッケージングをやり直したところ、WebMatrix でもインストール出来るようになりました!!