VisualStudio ItemTemplate 安装错误:值不在预期范围内

发布于 2024-11-01 03:19:42 字数 2303 浏览 7 评论 0原文

我编写了一些非常简单的 Visual Studio c# 项目模板。这些模板基于 VisualStudio 2010 SDK SP1。除一项模板外,一切正常;

经过一些细微的更改后,我尝试再次将模板应用到已经存在但又为空的单元测试项目,并收到以下错误:“值不在预期范围内。”该错误也出现在同一解决方案的其他一些项目中。

恢复项目模板中的更改会导致相同的错误。有些东西似乎被破坏了......经过大量的重建和 uninstallAddIn-closeVS-installAddIn-restartVS 我删除了现有的单元测试项目并创建了一个新的项目,其引用与旧的不工作的项目完全相同,并且一切正常。

以下是 template.vstemplate 文件内容:

<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
  <TemplateData>
    <Name>Tests</Name>
    <Description>No description available</Description>
    <Icon>TestsItems.ico</Icon>
    <TemplateID>662c9d07-0e83-4d4d-87d7-1fcc13667eb8</TemplateID>
    <ProjectType>CSharp</ProjectType>
    <RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
    <NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
    <DefaultName>EntityClass.cs</DefaultName>
  </TemplateData>
  <TemplateContent>
        <References>
            <Reference>
                <Assembly>System</Assembly>
            </Reference>
        </References>

    <ProjectItem TargetFileName="Controller/$fileinputname$ControllerTest.cs" ReplaceParameters="true">Controller/ControllerTest.cs</ProjectItem>
    <ProjectItem TargetFileName="Models/$fileinputname$RepositoryTest.cs" ReplaceParameters="true">Models/RepositoryTest.cs</ProjectItem>
  </TemplateContent>
</VSTemplate>

以下是其中一个类文件的内容

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NUnit.Framework;
using $rootnamespace$.Controllers;
using $rootnamespace$.Models;
using Assert = NUnit.Framework.Assert;
using IgnoreAttribute = Microsoft.VisualStudio.TestTools.UnitTesting.IgnoreAttribute;

namespace $rootnamespace$.Tests.Controllers
{
    /// <summary>
    /// Testclass for the $fileinputname$Controller
    /// </summary>
    [TestClass]
    public class $fileinputname$ControllerTest
    {

    }
}

附加说明:C# 项模板项目正在被 VSIX 项目使用。

有谁知道更多有关此错误及其发生原因的信息?

I have written a handful of very simple Visual Studio c# Item Templates. The templates are based on the VisualStudio 2010 SDK SP1. All works fine except one item template;

After some minor changes I've tried to apply the template again to the already existing but again empty Unit-test project and got the following error: "Value does not fall within the expected range." The error also occurred in some of the other projects of the same solution.

A revert of the changes in the item-template result in the same error. Something seems to be broken... After a lot of rebuilds and uninstallAddIn-closeVS-installAddIn-restartVS I removed the exiting Unit-test project and created a new one with exactly the same references as the old not working one and all works fine.

Here's the template.vstemplate file content:

<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
  <TemplateData>
    <Name>Tests</Name>
    <Description>No description available</Description>
    <Icon>TestsItems.ico</Icon>
    <TemplateID>662c9d07-0e83-4d4d-87d7-1fcc13667eb8</TemplateID>
    <ProjectType>CSharp</ProjectType>
    <RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
    <NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
    <DefaultName>EntityClass.cs</DefaultName>
  </TemplateData>
  <TemplateContent>
        <References>
            <Reference>
                <Assembly>System</Assembly>
            </Reference>
        </References>

    <ProjectItem TargetFileName="Controller/$fileinputname$ControllerTest.cs" ReplaceParameters="true">Controller/ControllerTest.cs</ProjectItem>
    <ProjectItem TargetFileName="Models/$fileinputname$RepositoryTest.cs" ReplaceParameters="true">Models/RepositoryTest.cs</ProjectItem>
  </TemplateContent>
</VSTemplate>

Here is the content of one of the class files

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NUnit.Framework;
using $rootnamespace$.Controllers;
using $rootnamespace$.Models;
using Assert = NUnit.Framework.Assert;
using IgnoreAttribute = Microsoft.VisualStudio.TestTools.UnitTesting.IgnoreAttribute;

namespace $rootnamespace$.Tests.Controllers
{
    /// <summary>
    /// Testclass for the $fileinputname$Controller
    /// </summary>
    [TestClass]
    public class $fileinputname$ControllerTest
    {

    }
}

One additional note: The C# Item Template Project is beeing consumed by a VSIX Project.

Does anyone know more about this error and why it occurs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙沙粒小 2024-11-08 03:19:42

就我而言,答案很简单:由于占位符名称错误而发生错误。

In my case the answer was quite simple; the error occurred due to bad placeholder names.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文