<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Submodule &#8211; Bubblog</title>
	<atom:link href="https://blog.yangyuanping.com/tag/submodule/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.yangyuanping.com</link>
	<description>nullable reference types</description>
	<lastBuildDate>Fri, 19 Dec 2025 18:17:21 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://blog.yangyuanping.com/wp-content/uploads/2025/11/cropped-patrick_log_logo_251121-2-32x32.png</url>
	<title>Submodule &#8211; Bubblog</title>
	<link>https://blog.yangyuanping.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>在 .Net 项目中使用 Git Submodule</title>
		<link>https://blog.yangyuanping.com/%e5%9c%a8-net-%e9%a1%b9%e7%9b%ae%e4%b8%ad%e4%bd%bf%e7%94%a8-git-submodule/</link>
		
		<dc:creator><![CDATA[peny911]]></dc:creator>
		<pubDate>Sat, 18 Oct 2025 05:04:12 +0000</pubDate>
				<category><![CDATA[未分类]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[Submodule]]></category>
		<guid isPermaLink="false">https://blog.yangyuanping.com/?p=945</guid>

					<description><![CDATA[在 .NET Core 项目中使用 Git Submodule 的场景通常是：你有一些公共的库、工具类、UI  [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>在 .NET Core 项目中使用 <strong>Git Submodule</strong> 的场景通常是：你有一些公共的库、工具类、UI 组件或 SDK，希望在多个项目中复用，同时又希望保持它们作为独立仓库进行开发和维护。这时候用 <strong>submodule</strong> 就很合适。下面是完整的使用步骤和注意事项。</p>
<hr />
<h2>一、添加 Submodule</h2>
<ol>
<li>在主项目仓库中执行：</li>
</ol>
<pre><code class="language-bash">git submodule add https://github.com/your-org/your-library.git src/YourLibrary</code></pre>
<ol start="2">
<li>初始化并更新 submodule：</li>
</ol>
<pre><code class="language-bash">git submodule update --init --recursive</code></pre>
<ol start="3">
<li>提交变更：</li>
</ol>
<pre><code class="language-bash">git add .gitmodules src/YourLibrary
git commit -m "Add submodule YourLibrary"</code></pre>
<hr />
<h2>二、在 .NET Core 项目中引用</h2>
<p>有两种常见方式：</p>
<h3>方式 1：直接作为项目引用</h3>
<ol>
<li>在主解决方案中添加子项目：</li>
</ol>
<pre><code class="language-bash">dotnet sln add src/YourLibrary/YourLibrary.csproj</code></pre>
<ol start="2">
<li>在主项目中引用：</li>
</ol>
<pre><code class="language-bash">dotnet add src/MainProject/MainProject.csproj reference src/YourLibrary/YourLibrary.csproj</code></pre>
<p>这样子模块的代码会直接参与编译和调试。</p>
<hr />
<h3>方式 2：作为 NuGet 包</h3>
<p>如果子模块仓库本身会打包成 NuGet 包，可以：</p>
<ol>
<li>在子模块目录里生成包：</li>
</ol>
<pre><code class="language-bash">cd src/YourLibrary
dotnet pack -c Release</code></pre>
<ol start="2">
<li>在主项目中添加本地源或上传到私有 NuGet Server，然后引用。</li>
</ol>
<p>这种方式更适合多人协作或多个项目依赖同一个库的场景。</p>
<hr />
<h2>三、更新 Submodule</h2>
<p>当子模块仓库有更新时：</p>
<pre><code class="language-bash">cd src/YourLibrary
git checkout main
git pull origin main
cd ../..
git add src/YourLibrary
git commit -m "Update YourLibrary submodule"</code></pre>
<p>主项目会记录子模块的 commit id。团队成员只需执行：</p>
<pre><code class="language-bash">git submodule update --init --recursive</code></pre>
<p>就能保持一致。</p>
<hr />
<h2>四、注意事项</h2>
<ol>
<li>
<p><strong>避免循环依赖</strong>：子模块不能再依赖主项目。</p>
</li>
<li>
<p><strong>团队协作</strong>：确保大家 clone 时用 &lt;code&gt;&#8211;recursive&lt;/code&gt;：</p>
<pre><code class="language-bash">git clone --recursive https://github.com/your-org/your-project.git</code></pre>
</li>
<li>
<p><strong>切换分支</strong>：记得子模块也可能需要单独切换分支。</p>
</li>
<li>
<p><strong>CI/CD</strong>：在 CI 脚本中要执行 &lt;code&gt;git submodule update &#8211;init &#8211;recursive&lt;/code&gt;。</p>
</li>
</ol>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
