VSIX Template Parameters not replacing correctly

I think I must be missing some glaringly obvious step here. I’m trying to build a VSIX template project for a C# .NET 8 executable. It works, all except the parameter replacement.

I have the following file in my template project:

DependencyInjection.cs (BuildAction: None, Copy to Output Directory: Do not copy)

using Microsoft.Extensions.DependencyInjection;
using $rootnamespace$.Repositories;

namespace $rootnamespace$;

public static class DependencyInjection
{
}

And I have the following line in my vstemplate file:

<ProjectItem ReplaceParameters="true" TargetFileName="DependencyInjection.cs">DependencyInjection.cs</ProjectItem>

However, when I use the template, I get the following DependencyInjection.cs file made for me, which is… not right, but not untouched. Looks like the token replacer did something, but not what I was hoping for.

using $
using Microsoft.Extensions.DependencyInjection;

rootnamespace$.Repositories;

namespace $rootnamespace$;
public static class DependencyInjection
{
}

What step did I miss? I’ve tried this with $defaultnamespace$ as well and got similar results. I feel like this is supposed to just work, so I must be missing something super obvious.

I followed your steps and tested at my side and found VSIX Template Parameters are replaced correctly. You can check the following steps to see if you missed something.

1.Have the file DependencyInjection.cs in your template project. Modify the code file to indicate where parameter replacement should take place.

2.On the Project menu, choose Export Template.

3.On the Choose Template Type page, choose Item Template, select the project that contains the item, and then choose Next.

4.Choose the item you want to create a template for, and then choose Next.

5 Have the following line in the vstemplate file:

  <ProjectItem SubType="" TargetFileName="$fileinputname$.cs" ReplaceParameters="true">DependencyInjection.cs</ProjectItem>

Test result:

For more information, please read docs :

Template parameters

Create Templates

2

After many hours of trial and error, I was able to identify the problem (no thanks to Microsoft’s docs).

The article on Template Parameters explicitly states

The following table lists the reserved template parameters that can be used by any template

That’s not the case though. Those templates parameters do not work for any template. Parameters which reference values that can only be known if a project is already existed, like $rootnamespace$ or $defaultnamespace$ don’t seem to work for items inside a Project Template. They only work for Item Templates when adding items to existing projects.

I solved my issue by using $safeprojectname$ as the parameter instead.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật