├── .gitattributes ├── .github └── workflows │ ├── PublishNuget.yml │ └── dotnetcore.yml ├── .gitignore ├── Directory.Build.props ├── LICENSE ├── README.md ├── README.zh-cn.md ├── build └── Version.props ├── docs ├── en-us │ └── README.md └── zh-cn │ ├── 2018-09-29-20-36-48.png │ ├── AttachFile.md │ ├── Behavior.md │ ├── DefaultIgnoreFile.md │ ├── IncludeSourceYardPackageReference.md │ ├── README.md │ ├── SourceYardExcludeFileItem.md │ ├── SourceYardExcludePackageReference.md │ ├── about.md │ └── get-started.md ├── dotnetCampus.SourceYard.sln ├── dotnetCampus.SourceYard.sln.DotSettings ├── sample ├── App │ ├── AppUsingDll │ │ ├── AppUsingDll.csproj │ │ └── Program.cs │ ├── AppUsingSource │ │ ├── AppUsingSource.csproj │ │ ├── Program.cs │ │ └── SourceProject │ │ │ └── .gitignore │ └── TheLib │ │ ├── Money.cs │ │ ├── Resource │ │ ├── F1.md │ │ └── F2.md │ │ ├── TheLib.csproj │ │ ├── foo.coin │ │ └── foo1.coin ├── Directory.Build.props ├── README.md ├── Sample.sln ├── WPF │ ├── WpfApp │ │ ├── App.xaml │ │ ├── App.xaml.cs │ │ ├── MainWindow.xaml │ │ ├── MainWindow.xaml.cs │ │ ├── Properties │ │ │ ├── AssemblyInfo.cs │ │ │ ├── Resources.Designer.cs │ │ │ ├── Resources.resx │ │ │ ├── Settings.Designer.cs │ │ │ └── Settings.settings │ │ ├── SourceProject │ │ │ └── .gitignore │ │ └── WpfApp.csproj │ └── WpfUI │ │ ├── InterestingControl.xaml │ │ ├── InterestingControl.xaml.cs │ │ └── WpfUI.csproj └── build │ └── Version.props ├── src └── dotnetCampus.SourceYard │ ├── Assets │ ├── Current │ │ ├── Core.targets │ │ ├── build │ │ │ ├── PackageId.props │ │ │ └── PackageId.targets │ │ └── buildMultiTargeting │ │ │ ├── PackageId.props │ │ │ └── PackageId.targets │ ├── README.md │ ├── README.zh-cn.md │ └── Target │ │ └── build │ │ ├── $(PackageId).SourceProject.props │ │ ├── $(PackageId).props │ │ └── $(PackageId).targets │ ├── Cli │ └── Options.cs │ ├── Context │ ├── IPackingContext.cs │ ├── MultiTargetingPackageInfo.cs │ ├── PackagedProjectFile.cs │ ├── PackingContext.cs │ ├── SourceYardPackageFile.cs │ └── TargetFrameworkPackageInfo.cs │ ├── Exception_ │ └── PackingException.cs │ ├── Logger_ │ ├── ILogger.cs │ └── Logger.cs │ ├── PackFlow │ ├── AssetsPacker.cs │ ├── IPackFlow.cs │ ├── ItemGroupPacker.cs │ ├── NuGetPacker.cs │ ├── NuspecFileGenerator.cs │ ├── NuspecFiles │ │ ├── DependenciesParser.cs │ │ └── NuspecContexts │ │ │ ├── NuspecDependency.cs │ │ │ ├── NuspecFrameworkAssembly.cs │ │ │ ├── NuspecGroup.cs │ │ │ ├── NuspecMetadata.cs │ │ │ └── NuspecPackage.cs │ ├── Package.cs │ └── SourcePacker.cs │ ├── Packer.cs │ ├── Program.cs │ ├── Utils │ ├── BuildProps.cs │ ├── CombineReadonlyList.cs │ ├── FileSystem.cs │ ├── ItemGroupElement.cs │ ├── ReferenceVersion.cs │ ├── SemanticVersion.cs │ └── VersionField.cs │ ├── dotnetCampus.SourceYard.csproj │ └── dotnetCampus.SourceYard.csproj.DotSettings └── tests ├── SourceYardLaunchSettingsDemo ├── Program.cs ├── Properties │ └── launchSettings.json └── SourceYardLaunchSettingsDemo.csproj ├── SourceYardTestDemo ├── Program.cs ├── SourceYardTestDemo.csproj └── SourceYardTestDemo.sln └── dotnetCampus.SourceYard.Tests └── dotnetCampus.SourceYard.Tests.csproj /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/workflows/PublishNuget.yml: -------------------------------------------------------------------------------- 1 | name: publish nuget 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: windows-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v1 15 | 16 | - name: Setup .NET Core 17 | uses: actions/setup-dotnet@v1 18 | with: 19 | dotnet-version: 3.1.202 20 | 21 | - name: Install tool 22 | run: dotnet tool install -g dotnetCampus.TagToVersion 23 | 24 | - name: Set tag to version 25 | run: dotnet TagToVersion -t ${{ github.ref }} 26 | 27 | - name: Build with dotnet 28 | run: dotnet build --configuration Release 29 | - name: Install Nuget 30 | run: | 31 | $sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" 32 | $targetNugetExe = "nuget.exe" 33 | Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe 34 | - name: Add private GitHub registry to NuGet 35 | run: | 36 | .\nuget sources add -name github -Source https://nuget.pkg.github.com/ORGANIZATION_NAME/index.json -Username ORGANIZATION_NAME -Password ${{ secrets.GITHUB_TOKEN }} 37 | - name: Push generated package to GitHub registry 38 | run: | 39 | .\nuget push .\bin\release\*.nupkg -Source github -SkipDuplicate 40 | .\nuget push .\bin\release\*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NugetKey }} -NoSymbols 41 | -------------------------------------------------------------------------------- /.github/workflows/dotnetcore.yml: -------------------------------------------------------------------------------- 1 | name: .NET Core 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: windows-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Setup .NET Core 13 | uses: actions/setup-dotnet@v1 14 | with: 15 | dotnet-version: 3.1.201 16 | - name: Build with dotnet 17 | run: dotnet build --configuration Release 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc 262 | /src/dotnetCampus.SourceYard/Properties/launchSettings.json 263 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildThisFileDirectory)bin\$(Configuration) 5 | dotnet-campus 6 | dotnet-campus 7 | latest 8 | false 9 | 10 | false 11 | Add a NuGet package only for dll reference? By using dotnetCampus.SourceYard, you can pack a NuGet package with source code. By installing the new source code package, all source codes behaviors just like it is in your project. 12 | Copyright (c) 2019-2021 dotnet-campus 13 | https://github.com/dotnet-campus/dotnetCampus.SourceYard 14 | https://github.com/dotnet-campus/dotnetCampus.SourceYard.git 15 | git 16 | source;dotnet;nuget;msbuild 17 | MIT 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018-2022 dotnet campus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dotnetCampus.SourceYard 2 | 3 | | Build | NuGet | 4 | |--|--| 5 | |![](https://github.com/dotnet-campus/SourceYard/workflows/.NET%20Core/badge.svg)|[![](https://img.shields.io/nuget/v/dotnetCampus.SourceYard.svg)](https://www.nuget.org/packages/dotnetCampus.SourceYard)| 6 | 7 | Add a NuGet package only for dll reference? By using dotnetCampus.SourceYard, you can pack a NuGet package with source code. By installing the new source code package, all source codes behaviors just like it is in your project. 8 | 9 | ## Getting Started 10 | 11 | ### Packing a source NuGet package 12 | 13 | Using NuGet tool to install [dotnetCampus.SourceYard](https://www.nuget.org/packages/dotnetCampus.SourceYard) to your project 14 | 15 | ``` 16 | PM> Install-Package dotnetCampus.SourceYard 17 | ``` 18 | 19 | Or 20 | 21 | ``` 22 | dotnet add package dotnetCampus.SourceYard 23 | ``` 24 | 25 | And then you should build your project and you will find the `*.Source.version.nupkg` file in your package output folder 26 | 27 | **Remark** 28 | 29 | The package with 0.1.19035-alpha version will break the double package reference project. 30 | 31 | If you want to support the double package reference project, you can use the package with 0.1.19033-alpha version. 32 | 33 | ## Documentation 34 | 35 | [简体中文](README.zh-cn.md) 36 | 37 | [NuGet shared source packages Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/dependencies#nuget-shared-source-packages ) 38 | 39 | ## Contributing 40 | 41 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/dotnet-campus/SourceYard/pulls) 42 | 43 | If you would like to contribute, feel free to create a [Pull Request](https://github.com/dotnet-campus/SourceYard/pulls), or give us [Bug Report](https://github.com/dotnet-campus/SourceYard/issues/new). 44 | 45 | ## Roadmap 46 | 47 | Check out this [Roadmap](https://github.com/dotnet-campus/SourceYard/projects/1) to learn about our development plans for 2021. 48 | 49 | ## Thanks 50 | 51 | - [@Zhuangkh](https://github.com/Zhuangkh) -------------------------------------------------------------------------------- /README.zh-cn.md: -------------------------------------------------------------------------------- 1 | # SourceYard 源码包 2 | 3 | | Build | NuGet | 4 | |--|--| 5 | |![](https://github.com/dotnet-campus/SourceYard/workflows/.NET%20Core/badge.svg)|[![](https://img.shields.io/nuget/v/dotnetCampus.SourceYard.svg)](https://www.nuget.org/packages/dotnetCampus.SourceYard)| 6 | 7 | SourceYard 提供制作源代码的 Nuget 包的方法,制作出来的源代码包可以被安装到任意的源代码兼容的项目。最后会合并到被安装的项目的程序集。 8 | 9 | 通过 SourceYard 可以分发简单的工具库,同时可以有效减少 DLL 的数量从而提升应用程序启动性能。因为 SourceYard 制作的是源代码包,制作出来的包具备良好的兼容性,通过宏等方法可以做到在各个平台使用相同的 Nuget 库。 10 | 11 | ## 快速入门 12 | 13 | 在项目中使用 NuGet 安装 [SourceYard](https://www.nuget.org/packages/dotnetCampus.SourceYard) 完成之后的每次编译生成,都可以在输出文件夹找到生成的 xx.source.1.0.0.nupkg 源代码包文件 14 | 15 | 将源代码包文件提交到 NuGet 源上,可以将此源代码包作为和普通的 NuGet 包一样在其他项目安装使用 16 | 17 | 以下是一个例子 18 | 19 | 创建一个空白的库程序 20 | 21 | ``` 22 | dotnet new console -o Foo 23 | ``` 24 | 25 | 在创建的项目里面安装 SourceYard 库 26 | 27 | ``` 28 | cd Foo 29 | dotnet add package dotnetCampus.SourceYard 30 | ``` 31 | 32 | 运行 dotnet build 命令进行编译,编译完成可以在 `bin\debug` 文件夹可以找到打包的源代码包 33 | 34 | **注意** 35 | 36 | 版本号是 0.1.19035-alpha 将会影响双包项目的使用,如需支持双包的项目请采用 0.1.19033-alpha 版本 37 | 38 | ## 文档 39 | 40 | [中文文档](./docs/zh-cn) 41 | 42 | [微软官方文档 NuGet 共享源代码包](https://docs.microsoft.com/zh-cn/dotnet/standard/library-guidance/dependencies#nuget-shared-source-packages ) 43 | 44 | ## 例子 45 | 46 | [例子代码](./sample) 47 | 48 | ## 开源社区 49 | 50 | 如果你希望参与贡献,欢迎 [Pull Request](https://github.com/dotnet-campus/SourceYard/pulls),或给我们 [报告 Bug](https://github.com/dotnet-campus/SourceYard/issues/new) 51 | 52 | ## 规划 53 | 54 | 查看[这个页面](https://github.com/dotnet-campus/SourceYard/projects/1) 来了解我们 2020 年的开发计划 55 | 56 | ## 授权协议 57 | 58 | [![](https://img.shields.io/badge/License-MIT-blue?style=flat-square)](https://github.com/dotnet-campus/SourceYard/blob/master/LICENSE) -------------------------------------------------------------------------------- /build/Version.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0.1.19393-alpha13 4 | 5 | 6 | -------------------------------------------------------------------------------- /docs/en-us/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-campus/SourceYard/3480efbb3afe425a82f34d46210be39ad9b40e63/docs/en-us/README.md -------------------------------------------------------------------------------- /docs/zh-cn/2018-09-29-20-36-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-campus/SourceYard/3480efbb3afe425a82f34d46210be39ad9b40e63/docs/zh-cn/2018-09-29-20-36-48.png -------------------------------------------------------------------------------- /docs/zh-cn/AttachFile.md: -------------------------------------------------------------------------------- 1 | # 附加文件 2 | 3 | 将额外的文件加入到 SourceYard 源代码包 4 | 5 | 加入某个文件夹的所有文件的方法如下 6 | 7 | ``` 8 | 9 | 10 | 11 | ``` -------------------------------------------------------------------------------- /docs/zh-cn/Behavior.md: -------------------------------------------------------------------------------- 1 | # 行为和配置 2 | 3 | ## 术语 4 | 5 | 源代码包: 将源代码打包到 NuGet 文件,也就是 SourceYard 工具的输出文件 6 | 7 | 库项目: 用于打出源代码包的项目 8 | 9 | 目标项目: 安装上某个源代码包的项目 10 | 11 | ## 特殊配置 12 | 13 | 在 SourceYard 打出的源代码包中,可以通过一些特殊的配置实现源代码包特殊的功能 14 | 15 | ### DisableSourcePackageAutoPrivateAssets 16 | 17 | 禁止自动配置目标全部源代码包自动设置 PrivateAssets 属性,默认的源代码将会自动添加如下代码 18 | 19 | ```xml 20 | 21 | 22 | 23 | 24 | all 25 | all 26 | 27 | 28 | ``` 29 | 30 | 可以通过在 `目标项目` 上设置 DisableSourcePackageAutoPrivateAssets 属性为 true 禁用当前项目全部安装的源代码包自动设置 31 | 32 | 以上的 `#(PackageId)` 就是对应的安装的源代码包,如 `TheLib.Source` 等 33 | 34 | 如需要对具体某个源代码包进行配置,请自行设置更新覆盖即可 -------------------------------------------------------------------------------- /docs/zh-cn/DefaultIgnoreFile.md: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件和文件夹 2 | 3 | ```csharp 4 | /// 5 | /// 忽略的文件夹列表 6 | /// 7 | private static IList IgnoreFolderList { get; } = new List() 8 | { 9 | ".vs", "bin", "obj", ".git", "x64", "x86" 10 | }; 11 | 12 | /// 13 | /// 忽略的文件后缀列表 14 | /// 15 | private static IList IgnoreFileEndList { get; } = new List() 16 | { 17 | ".csproj.DotSettings", ".suo", ".user", ".sln.docstates", 18 | ".nupkg", 19 | // 忽略原因请看 https://github.com/dotnet-campus/SourceYard/issues/98 20 | "launchSettings.json" 21 | }; 22 | ``` -------------------------------------------------------------------------------- /docs/zh-cn/IncludeSourceYardPackageReference.md: -------------------------------------------------------------------------------- 1 | # 引用源代码包依赖的原理 2 | 3 | 在 `$(PackageId).props` 文件,也就是会在打包的时候,放在打出的源代码包,作为对应的源代码包的 Build 文件夹里面控制构建的 props 文件,在这个文件里面将当前源代码包的包 Id 加入到 SourceYardPackageReference 属性里面,如下面代码 4 | 5 | ```xml 6 | 7 | 8 | $(SourceYardPackageReference);#(PackageId) 9 | 10 | ``` 11 | 12 | 这样在其他的项目,安装了源代码包,就可以通过 SourceYardPackageReference 属性了解当前项目安装了哪些源代码包 13 | 14 | 例如有项目 A 安装了 B 源代码包,那么通过 SourceYardPackageReference 属性就能拿到 B 源代码包 15 | 16 | 在将安装了源代码包的项目打包为源代码包时,例如将上面的 A 项目打包为源代码包时,想要添加 B 源代码包的引用依赖,就可以通过 SourceYardPackageReference 属性拿到当前 A 项目安装的源代码包,将这些源代码加入到依赖中 17 | 18 | 添加源代码包依赖的逻辑放在 Core.targets 里,将 SourceYardPackageReference 属性写入到 SourceYardPackageReferenceFile 文件里面 19 | 20 | ```xml 21 | 22 | ``` 23 | 24 | 这个 SourceYardPackageReferenceFile 文件将会在 BuildProps 里面读取然后加入引用依赖 -------------------------------------------------------------------------------- /docs/zh-cn/README.md: -------------------------------------------------------------------------------- 1 | # SourceYard 源码包 2 | 3 | [SourceYard](about.md) 是[开源](https://github.com/dotnet-campus/SourceYard/blob/master/LICENSE)的 NuGet 源码包制作工具。它本质上也是一个 NuGet 包,当你将其安装到你的项目中后,可以为你的项目打出一个不同于原生 NuGet 包的特殊包,此包仅包含你项目中的源码而没有 dll 引用。 4 | 5 | SourceYard 适用于 .NET 项目,无论是 .NET Core 还是 .NET Framework 或者是 .NET Standard。实际上它是一个用于开发阶段使用的 NuGet 包,所以也几乎可以无视所用的平台,只要你的开发环境中具有 .NET Core 运行时即可。 6 | 7 | ## 上手 SourceYard 8 | 9 | [SourceYard](https://www.nuget.org/packages/SourceYard/) 已发布到 [nuget.org](https://nuget.org/)。 10 | 11 | 在 Visual Studio 项目中,打开 NuGet 包管理器,搜索 SourceYard,将其安装。当你开始编译项目的时候,即可以在输出目录下找到 `*.Source.nupkg` 包,这便是源码包。 12 | 13 | 关于如何打一个源码包以及如何安装和使用源码包,请阅读: 14 | 15 | - [入门](get-started.md) 16 | 17 | -------------------------------------------------------------------------------- /docs/zh-cn/SourceYardExcludeFileItem.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dotnet-campus/SourceYard/3480efbb3afe425a82f34d46210be39ad9b40e63/docs/zh-cn/SourceYardExcludeFileItem.md -------------------------------------------------------------------------------- /docs/zh-cn/SourceYardExcludePackageReference.md: -------------------------------------------------------------------------------- 1 | # SourceYardExcludePackageReference 2 | 3 | 排除的依赖引用 4 | 5 | 在打源代码包的时候,有一些 NuGet 引用依赖不期望被加入源代码的依赖,以提升源代码包的兼容性 6 | 7 | 此时可以采用 SourceYardExcludePackageReference 机制,在 SourceYardExcludePackageReference 项里面添加的 NuGet 包 Id 内容,将不会被加入源代码包引用依赖 8 | 9 | 例如有项目 A 引用了两个 NuGet 包,分别是 B 和 C 库 10 | 11 | ```xml 12 | 13 | 14 | 15 | 16 | ``` 17 | 18 | 而项目 A 不期望打出的源代码包,包含了 B 和 C 库的依赖。可以在项目文件里面添加 SourceYardExcludePackageReference 列表,如下面代码 19 | 20 | ```xml 21 | 22 | 23 | 24 | 25 | ``` 26 | 27 | 此时打包出来的源代码包将不会包含 B 和 C 库的依赖 -------------------------------------------------------------------------------- /docs/zh-cn/about.md: -------------------------------------------------------------------------------- 1 | # 关于 SourceYard 2 | 3 | SourceYard 具有如下特点: 4 | 5 | - 将源代码打包到 NuGet 包中 6 | - 和安装其他 NuGet 包一样安装,无须额外的安装知识 7 | - 可以直接跳转源代码且可编辑调试断点 -------------------------------------------------------------------------------- /docs/zh-cn/get-started.md: -------------------------------------------------------------------------------- 1 | # 入门 2 | 3 | 源码包的使用分为两个部分: 4 | 5 | 1. 源码包打包 6 | 1. 安装和使用源码包 7 | 8 | ## 源码包打包 9 | 10 | 我们现在从零开始创建一个项目,然后将其打包成源码包。 11 | 12 | ### 第一步:新建一个项目,或者打开现有项目 13 | 14 | 创建项目是 Visual Studio 开发的必备步骤,所以这里只做简单描述。 15 | 16 | ![创建一个新项目](2018-09-29-20-36-48.png) 17 | 18 | 在项目中,我们只新建一个简单的类型 `Foo` 用来演示: 19 | 20 | ```csharp 21 | using System; 22 | 23 | namespace dotnetCampus.Demo.Library 24 | { 25 | /// 26 | /// This class is packaged as a source reference so it will be compiled into your own project. 27 | /// 28 | public class Foo 29 | { 30 | /// 31 | /// Print hello to the specifed . 32 | /// 33 | /// The name which will say hello to. 34 | public void PrintHello(string name) 35 | { 36 | Console.WriteLine($"Hello {name}"); 37 | } 38 | } 39 | } 40 | ``` 41 | 42 | 项目中其实也只有这一个类而已: 43 | 44 | ``` 45 | - dotnetCampus.Demo.Library.csproj 46 | - Foo.cs 47 | ``` 48 | 49 | ## 安装和使用源代码打包 50 | 51 | 可以通过命令行或 VisualStudio 的 NuGet 管理器安装 [SourceYard](https://www.nuget.org/packages/dotnetCampus.SourceYard) 52 | 53 | 在安装完成之后,不需要任何配置,请右击项目进行编译 54 | 55 | 编译完成可以在输出路径,如 `bin\debug` 看到 `dotnetCampus.Demo.Library.Source.1.0.0.nupkg` 源代码包 56 | 57 | ## 使用源码包 58 | 59 | 再次新建或打开一个项目,接下来演示在这个项目安装和使用上一步打出来的源代码包 60 | 61 | 先在 VisualStudio 设置 NuGet 添加 `dotnetCampus.Demo.Library.Source.1.0.0.nupkg` 所在的文件夹 62 | 63 | 此时就可以在项目里面通过 NuGet 安装 dotnetCampus.Demo.Library.Source 库 64 | 65 | 尝试在新打开的项目里面使用 `dotnetCampus.Demo.Library.Foo` 方法 66 | 67 | ```csharp 68 | var foo = new dotnetCampus.Demo.Library.Foo(); 69 | foo.PrintHello("dotnet campus"); 70 | ``` 71 | 72 | 尝试运行项目,将发现可以执行到 PrintHello 方法,同时支持断点调试到方法里面代码 73 | 74 | 打开项目的输出文件夹,可以看到在文件夹里面不存在 `dotnetCampus.Demo.Library.dll` 因为此时源代码包是作为源代码引用 75 | 76 | 例子用到的源代码参见 [sample](../../sample/App) -------------------------------------------------------------------------------- /dotnetCampus.SourceYard.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29503.13 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.SourceYard", "src\dotnetCampus.SourceYard\dotnetCampus.SourceYard.csproj", "{E0E10F18-8AB9-4DC5-A68C-17726D619F24}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{075C3F7B-E00A-49D7-9D48-7F7DE6E2D4BC}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{75DA54C8-4888-4347-AF63-8E4C2CFB4D2C}" 11 | ProjectSection(SolutionItems) = preProject 12 | .gitattributes = .gitattributes 13 | .gitignore = .gitignore 14 | Directory.Build.props = Directory.Build.props 15 | LICENSE = LICENSE 16 | README.md = README.md 17 | build\Version.props = build\Version.props 18 | EndProjectSection 19 | EndProject 20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.SourceYard.Tests", "tests\dotnetCampus.SourceYard.Tests\dotnetCampus.SourceYard.Tests.csproj", "{40CA62ED-6DFF-4A65-93D4-A91AB5DCF9DE}" 21 | EndProject 22 | Global 23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 24 | Debug|Any CPU = Debug|Any CPU 25 | Release|Any CPU = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 28 | {E0E10F18-8AB9-4DC5-A68C-17726D619F24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {E0E10F18-8AB9-4DC5-A68C-17726D619F24}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {E0E10F18-8AB9-4DC5-A68C-17726D619F24}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {E0E10F18-8AB9-4DC5-A68C-17726D619F24}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {40CA62ED-6DFF-4A65-93D4-A91AB5DCF9DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {40CA62ED-6DFF-4A65-93D4-A91AB5DCF9DE}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {40CA62ED-6DFF-4A65-93D4-A91AB5DCF9DE}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {40CA62ED-6DFF-4A65-93D4-A91AB5DCF9DE}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(NestedProjects) = preSolution 41 | {40CA62ED-6DFF-4A65-93D4-A91AB5DCF9DE} = {075C3F7B-E00A-49D7-9D48-7F7DE6E2D4BC} 42 | EndGlobalSection 43 | GlobalSection(ExtensibilityGlobals) = postSolution 44 | SolutionGuid = {7117963B-299E-4A6F-AFC6-D82B83656776} 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /dotnetCampus.SourceYard.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | SDK 3 | True 4 | True 5 | True -------------------------------------------------------------------------------- /sample/App/AppUsingDll/AppUsingDll.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net45 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /sample/App/AppUsingDll/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using TheLib; 3 | 4 | namespace AppUsingDll 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | var money = new Money(12312); 11 | Console.WriteLine(money.ToCapital()); 12 | Console.ReadLine(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sample/App/AppUsingSource/AppUsingSource.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | net45;net5.0 6 | Exe 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample/App/AppUsingSource/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using TheLib; 4 | 5 | namespace AppUsingSource 6 | { 7 | class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | var money = new Money(12312); 12 | var v = (money, "123"); 13 | Console.WriteLine(v); 14 | 15 | #if NET45 16 | var dependencyObject = new DependencyObject(); 17 | #endif 18 | 19 | Console.WriteLine(money.ToCapital()); 20 | Console.ReadLine(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sample/App/AppUsingSource/SourceProject/.gitignore: -------------------------------------------------------------------------------- 1 | *.Source.SourceProject.props -------------------------------------------------------------------------------- /sample/App/TheLib/Money.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace TheLib 6 | { 7 | /// 8 | /// 人民币转大写 9 | /// 10 | public class Money 11 | { 12 | public Money(double money) 13 | { 14 | _money = money; 15 | } 16 | 17 | public string ToCapital() 18 | { 19 | if (Math.Abs(_money) < 0.0001) 20 | { 21 | return "零元"; 22 | } 23 | 24 | var str = GetIntPart(); 25 | GetDecimalPart(str); 26 | return str.ToString(); 27 | } 28 | 29 | private static readonly List Uppers = new List() 30 | { 31 | '零', 32 | '壹', 33 | '贰', 34 | '叁', 35 | '肆', 36 | '伍', 37 | '陆', 38 | '柒', 39 | '捌', 40 | '玖' 41 | }; 42 | 43 | private static readonly List Units = new List() 44 | { 45 | '分', 46 | '角' 47 | }; 48 | 49 | private static readonly List Grees = new List() 50 | { 51 | '元', 52 | '拾', 53 | '佰', 54 | '仟', 55 | '万', 56 | '拾', 57 | '佰', 58 | '仟', 59 | '亿', 60 | '拾', 61 | '佰', 62 | '仟', 63 | '万', 64 | '拾', 65 | '佰' 66 | }; 67 | 68 | private readonly double _money; 69 | 70 | private StringBuilder GetIntPart() 71 | { 72 | StringBuilder str = new StringBuilder(); 73 | var money = _money; 74 | 75 | for (int i = 0; money > 0.99999; i++) 76 | { 77 | var n = (int)(money % 10); 78 | str.Insert(0, Grees[i]); 79 | str.Insert(0, Uppers[n]); 80 | money = money / 10; 81 | money = money - (n / 10.0); 82 | } 83 | 84 | str = str.Replace("零亿", "亿零"); 85 | str = str.Replace("零万", "万零"); 86 | 87 | str = str.Replace("零拾", "零"); 88 | str = str.Replace("零佰", "零"); 89 | str = str.Replace("零仟", "零"); 90 | 91 | str = str.Replace("零零", "零"); 92 | str = str.Replace("零零", "零"); 93 | 94 | str = str.Replace("零亿", "亿"); 95 | str = str.Replace("零万", "万"); 96 | str = str.Replace("零元", "元"); 97 | 98 | return str; 99 | } 100 | 101 | private void GetDecimalPart(StringBuilder str) 102 | { 103 | var money = _money * 100; 104 | for (int i = 0; i < 2; i++) 105 | { 106 | var n = (int)(money % 10); 107 | if (n != 0) 108 | { 109 | str.Insert(0, Units[i]); 110 | str.Insert(0, Uppers[n]); 111 | } 112 | 113 | money = money / 10; 114 | } 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /sample/App/TheLib/Resource/F1.md: -------------------------------------------------------------------------------- 1 | # F1 -------------------------------------------------------------------------------- /sample/App/TheLib/Resource/F2.md: -------------------------------------------------------------------------------- 1 | # F2 -------------------------------------------------------------------------------- /sample/App/TheLib/TheLib.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net45 5 | true 6 | 7 | 8 | 9 | 10 | all 11 | runtime; build; native; contentfiles; analyzers 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /sample/App/TheLib/foo.coin: -------------------------------------------------------------------------------- 1 | > Foo -------------------------------------------------------------------------------- /sample/App/TheLib/foo1.coin: -------------------------------------------------------------------------------- 1 | > Foo -------------------------------------------------------------------------------- /sample/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildThisFileDirectory)bin\$(Configuration) 5 | $(MSBuildThisFileDirectory)bin\app\$(MSBuildProjectName)\ 6 | dotnet campus 7 | lindexi;吕毅 8 | https://github.com/dotnet-campus/SourceYard 9 | git 10 | https://github.com/dotnet-campus/SourceYard 11 | Copyright © 2018-2021 dotnet campus All Rights Reserved. 12 | SourceYard 13 | 14 | -------------------------------------------------------------------------------- /sample/README.md: -------------------------------------------------------------------------------- 1 | # SourceYard 制作源代码包 2 | 3 | 本文带大家走进SourceYard开发之旅 4 | 5 | 6 | 在项目开发中,将一个大的项目拆为多个小项目解耦,减少模块之间的耦合。因为如果将代码放在一起,即使有团队的约束,但只要能写出的代码就会有小伙伴写出,很快就发现各个模块耦合的代码很多。但是对一个项目的拆分会让拆分出来的每一个项目都编译出一个 dll 增加运行文件的启动时间。 7 | 8 | 在开发中,常常会用到很多工具类,这些小轮子很多的功能基本就只有一个类,如何对这些小轮子进行管理?通过复制代码还是通过 Nuget 管理? 9 | 10 | 11 | 12 | 13 | 如果使用复制代码的方式,很难知道从哪里复制代码,如果在很多项目都复制了代码,发现原来的代码存在一些虫子,很难修改所有复制代码的项目。通过传统 Nuget 的方式可以方便管理工具的更新,和引入工具,同时会将每个小轮子打包成一个 dll 这样会引入很多 dll 让软件启动的速度和运行的速度降低。关于 dll 数量和启动时间的测试请看 [C# 程序集数量对软件启动性能的影响](https://lindexi.gitee.io/post/C-%E7%A8%8B%E5%BA%8F%E9%9B%86%E6%95%B0%E9%87%8F%E5%AF%B9%E8%BD%AF%E4%BB%B6%E5%90%AF%E5%8A%A8%E6%80%A7%E8%83%BD%E7%9A%84%E5%BD%B1%E5%93%8D.html ) 介绍了程序集数量对软件启动性能的影响,运行的性能是在引用某个 dll 方法的时候需要加载这个 dll 降低速度。 14 | 15 | 有小伙伴问,为何不将所有的工具放在一个大的项目,这样每次只需要更新大项目的 Nuget 就可以,这样就可以解决引入dll的数量和管理小工具。 16 | 17 | 虽然将很多的工具放在一个程序集做一个 Nuget 的方式看起来不错,但是只是在很小的项目同时不能维护太久,在我现在的团队有一个库,这个库就是用来放小工具,但是在经过了一段时间,发现基本上所有小伙伴在不知道要将类放在哪个地方的时候,就会放在这个程序集里。同时因为所有工具都在一个程序集里,所有小工具都在相互引用。在我想要修复某个小工具的功能的时候,发现在这个程序集内这个工具已经有 99 引用,其中还有不少地方依赖 bug 编程,这时维护这样一个程序集的成功非常高,同时无法组织小伙伴不断将含义不明确的类放在这个程序集(这里不是在讨论代码审查问题,在我现在的团队是有明确的代码审查,然而没有人能说清这个程序集的功能),所以这就是为什么不建议所有小工具放在一个程序集的原因。另外如果都将代码放在一个程序集,用于分享也是比较难,有小伙伴向我要一些工具,假设我都放在一个程序集里,那么我只能通过拷贝代码的方式给他,因为我不确定工具程序集里面是否有不能对外发布的内容,但如果是 SourceYard 的方法,作为源代码包可以将小伙伴需要的工具发布到 Nuget.org 请他去安装。 18 | 19 | 当然将工具放在一个工具程序集也不是没有优点,因为所有的工具都在一个程序集里面,小伙伴可以方便找到自己需要的类,而不是通过 Nuget 的方式去寻找安装。同时如果有一个项目多个程序集需要相同的工具,可以同时依赖工具程序集,减少创建出来的 dll 文件里重复代码。 20 | 21 | 解决上面的两个问题的方法是通过 SourceYard 的方法,使用 SourceYard 不但可以解决项目解耦创建了很多个项目让很多个项目编译出来的 dll 太多让软件启动性能降低,同时解决小工具类太多的问题,还可以解决代码兼容的问题。 22 | 23 | ## 控制台项目 24 | 25 | 创建一个 dotnet core 项目进行开发,这里创建一个 dotnet core 项目主要是因为创建出来的项目清真 26 | 27 | 假设有一个需求是做一个工具,这个工具的功能是用户输入数字,转换为人民币金额大写,听起来这个功能很简单,当然在本文就不会详细告诉大家这个工具的代码。 28 | 29 | 30 | 31 | ![](http://image.acmx.xyz/lindexi%2F201812911718537) 32 | 33 | 在我之前的博客[C# 金额转中文大写](https://lindexi.gitee.io/post/C-%E9%87%91%E9%A2%9D%E8%BD%AC%E4%B8%AD%E6%96%87%E5%A4%A7%E5%86%99.html )已经有了代码,可以从[码云复制](https://gitee.com/lindexi/codes/w6bxlue9o14rv5nscjyhf20 ) 复制的代码因为没有命名空间,需要手动添加,于是现在就创建了一个项目,这个项目包含一个类。 34 | 35 | 36 | 37 | ![](http://image.acmx.xyz/lindexi%2F2018129111242105) 38 | 39 | 使用 SourceYard 很简单,只需要在 TheLib 项目管理 Nuget 安装 SourceYard 就可以 40 | 41 | 42 | 43 | ![](http://image.acmx.xyz/lindexi%2F2018129111349653) 44 | 45 | 现在 SourceYard 还没正式发布,里面还存在一些坑,但是对于这么简单的项目已经可以使用。 46 | 47 | 如果对 SourceYard 感兴趣,请在 [github](https://github.com/dotnet-campus/SourceYard ) 关注 48 | 49 | 右击 TheLib 的属性,在打包的页面勾选在版本中生成 Nuget 包,勾选之后重新编译就可以制作出 Nuget 包。但是请不要急,在打包页面还有很多东西需要填写,在[广州 .NET 微软技术俱乐部12月份活动](http://www.10tiao.com/html/391/201811/2654072986/1.html) 的演示中,我使用了[这个黑科技](https://lindexi.gitee.io/post/Roslyn-%E5%B0%86%E8%BF%99%E4%B8%AA%E6%96%87%E4%BB%B6%E6%94%BE%E5%9C%A8%E4%BD%A0%E7%9A%84%E9%A1%B9%E7%9B%AE%E6%96%87%E4%BB%B6%E5%A4%B9-%E6%97%A0%E8%AE%BA%E5%93%AA%E4%B8%AA%E6%8E%A7%E5%88%B6%E5%8F%B0%E9%A1%B9%E7%9B%AE%E9%83%BD%E4%BC%9A%E8%BE%93%E5%87%BA%E6%9E%97%E5%BE%B7%E7%86%99%E6%98%AF%E9%80%97%E6%AF%94.html )瞬间完成了所有属性,小伙伴如果还没学会这个黑科技就需要手动填写内容了,其实只有作者、公司、说明是必要的,其他的可以不写。 50 | 51 | 52 | 53 | ![](http://image.acmx.xyz/lindexi%2F2018129111533228) 54 | 55 | 如果需要将 TheLib 修改为 dotnet framework 的项目,只需要右击编辑 csproj 文件就可以,在[理解 C# 项目 csproj 文件格式的本质和编译流程](https://walterlv.gitee.io/post/understand-the-csproj.html )和[广州 .NET 微软技术俱乐部12月份活动](http://www.10tiao.com/html/391/201811/2654072986/1.html) 吕毅都讲了项目的格式,如果只需要修改 dotnet framework 不需要了解那么多,只需要在 TargetFramework 里面修改为 net45 就完成 56 | 57 | ``` 58 | 59 | 60 | 61 | net45 62 | true 63 | 64 | 65 | 66 | 67 | all 68 | runtime; build; native; contentfiles; analyzers 69 | 70 | 71 | 72 | 73 | ``` 74 | 75 | 现在右击项目重新编译就可以打出 Nuget 包,在使用新的项目格式,默认的 dotnet core 项目就是这么简单,具体请看[VisualStudio 使用新项目格式快速打出 Nuget 包](https://lindexi.gitee.io/post/VisualStudio-%E4%BD%BF%E7%94%A8%E6%96%B0%E9%A1%B9%E7%9B%AE%E6%A0%BC%E5%BC%8F%E5%BF%AB%E9%80%9F%E6%89%93%E5%87%BA-Nuget-%E5%8C%85.html )详细写了黑科技 76 | 77 | 在输出的文件夹可以找到打包的 Nuget 文件 78 | 79 | 80 | 81 | ![](http://image.acmx.xyz/lindexi%2F2018129112917582) 82 | 83 | 文件可以通过 [Nuget 管理器](https://www.microsoft.com/store/productId/9WZDNCRDMDM3) 打开,这个文件可以在应用商店找到 84 | 85 | 86 | 87 | ![](http://image.acmx.xyz/lindexi%2F2018129113026481) 88 | 89 | 这里两个不同的文件,其他是传统的 Nuget 包,也就是 TheLib.1.0.2.nupkg 里面包含 dll 请打开文件很快就可以看到 90 | 91 | 92 | 93 | ![](http://image.acmx.xyz/lindexi%2F2018129113243747) 94 | 95 | 源代码的文件的格式也请小伙伴打开看一下,里面没有 dll 里面是代码,在安装这个文件就会引用代码,代码会编译在引用的项目。多个不同的源代码包会编译为一个程序集。 96 | 97 | 98 | 99 | ![](http://image.acmx.xyz/lindexi%2F201812911383738) 100 | 101 | 虽然有 Nuget 文件但是还不知道这个文件能不能使用,创建两个不同的项目用来用这两个文件,因为刚才已经修改项目为 dotnet framework 的,就需要创建一个 dotnet framework 的项目 102 | 103 | 104 | 105 | ![](http://image.acmx.xyz/lindexi%2F2018129115048210) 106 | 107 | 右击项目管理 Nuget 引用本地的 Nuget 文件的文件夹,如我这里的 Nuget 文件是在 `D:\lindexi\SourceYard\bin\Debug` 文件夹下,我就需要添加这样的路径,请看图片 108 | 109 | 110 | 111 | ![](http://image.acmx.xyz/lindexi%2F2018129115544606) 112 | 113 | 这里的程序包源的名称是可以随意给的,程序员最难的就是命名,好在有[Whitman](https://www.microsoft.com/store/productId/9P8LNZRNJX85 ) 这个工具可以按下 ctrl+, 输入第一个字符为小写的变量,按下 ctrl+shift+, 输入第一个字符为大写的变量。现在这个工具已经从 dotnet framework 升级到 dotnet core 请看 [将基于 .NET Framework 的 WPF 项目迁移到基于 .NET Core 3 - walterlv](https://walterlv.gitee.io/post/migrate-wpf-project-from-dotnet-framework-to-dotnet-core.html ) 关于 WPF 怎么可以在 dotnet core 运行,微软已经将 WPF 的 dotnet core 开源,可以在 [github](https://github.com/dotnet/wpf ) 找到 114 | 115 | 现在点击本地的源,如刚才命名为 TacaluTawnenai 的源就可以找到刚才的两个文件,如何选择本地的源?请看下图,点击程序包源的下拉就可以找到 116 | 117 | 118 | 119 | ![](http://image.acmx.xyz/lindexi%2F201812912055633) 120 | 121 | 刚才创建的 dotnet framework 程序还是比较不清真的,先进行卸载,然后编辑 csproj 文件,可以看到这里的文件内容非常多,这是很不清真的。从刚才的 TheLib 文件里面拷贝 csproj 文件到 AppUsingDll 项目里,记得需要先去掉 SourceYard 的部分 122 | 123 | ``` 124 | 125 | 126 | 127 | net45 128 | true 129 | 130 | 131 | 132 | 133 | all 134 | runtime; build; native; contentfiles; analyzers 135 | 136 | 137 | 138 | 139 | ``` 140 | 141 | 将上面不需要的部分,也就是引用 SourceYard 包的部分和 GeneratePackageOnBuild 去掉,现在剩下的代码很少 142 | 143 | ``` 144 | 145 | 146 | 147 | net45 148 | 149 | 150 | ``` 151 | 152 | 控制台项目需要做很小的修改,通过右击项目属性,在界面选择控制台 153 | 154 | 155 | 156 | ![](http://image.acmx.xyz/lindexi%2F201812913059674) 157 | 158 | 如果此时进行编译会看到编译不通过,因为还需要删除 AssemblyInfo.cs 文件的很多代码,其实可以直接删除这个文件 159 | 160 | 在这个项目需要安装 TheLib 库,安装的方式和安装其他的 Nuget 没有不同,通过本地的文件夹安装 Nuget 包和通过 Nuget 服务器安装没有不同,如果需要自己搭建 Nuget 服务器也是十分简单,请看[通过ProGet搭建一个内部的Nuget服务器 - 张善友 - 博客园](http://www.cnblogs.com/shanyou/p/5910250.html )我就帮小伙伴在10分钟内搭建 Nuget 服务器 161 | 162 | 163 | 164 | ![](http://image.acmx.xyz/lindexi%2F201812912055633) 165 | 166 | 安装之后添加一点代码测试一下能否使用 167 | 168 | ```csharp 169 | var money = new Money(12312); 170 | Console.WriteLine(money.ToCapital()); 171 | Console.ReadLine(); 172 | ``` 173 | 174 | 这时运行一下,可以看到成功运行了。 175 | 176 | 再创建一个项目,这个项目尝试使用 dotnet core 的项目 177 | 178 | 179 | 180 | ![](http://image.acmx.xyz/lindexi%2F2018129143342731) 181 | 182 | 右击项目管理 Nuget 安装源代码包,然后在主函数添加相同的测试代码 183 | 184 | 185 | 186 | ![](http://image.acmx.xyz/lindexi%2F2018129143448185) 187 | 188 | ```csharp 189 | static void Main(string[] args) 190 | { 191 | var money = new Money(12312); 192 | Console.WriteLine(money.ToCapital()); 193 | Console.ReadLine(); 194 | } 195 | ``` 196 | 197 | 现在尝试运行,可以看到和刚才的 dotnet framework 控制台输出相同 198 | 199 | 但是有一点不相同的是,打开两个项目的输出文件夹,可以看到 dotnet framework 项目引用的是 dll 的方式,输出的文件夹有一个dll和一个exe 在 dotnet core 项目的输出文件夹只有一个 dll 因为默认的 dotnet core 输出的是 dll 源代码就放在相同的 dll 里 200 | 201 | 202 | 203 | ![](http://image.acmx.xyz/lindexi%2F201812914371424) 204 | 205 | 206 | 207 | ![](http://image.acmx.xyz/lindexi%2F2018129143741224) 208 | 209 | 这时就可以看到 SourceYard 的好处,通过 SourceYard 可以将源代码作为 Nuget 包,这样不但减少 dll 的数量,同时做到源代码的兼容。在之前,无论是PCL还是多项目方式的 Nuget 包管理多个不同平台的兼容难度比较大,但是通过 SourceYard 只要源代码可以兼容就可以安装。在本文的控制台的使用的库是 dotnet framework 4.5 但是控制台项目使用的是 dotnet core 2.1 的,这样都可以使用。 210 | 211 | ## WPF 程序 212 | 213 | 如果小伙伴觉得控制台还是太简单了,可以尝试使用桌面WPF程序,此时 WinForms 程序也是适合的。 214 | 215 | 创建一个简单的 WPF 库,注意创建之后需要修改代码,修改项目格式为 VisualStudio 2017 格式 216 | 217 | 在开始编辑之前,先创建一个用户控件,这里叫 InterestingControl 一个有趣的控件,同时删除 Properties 文件夹的所有文件 218 | 219 | 220 | 221 | ![](http://image.acmx.xyz/lindexi%2F2018129144418506) 222 | 223 | 相对来说,做 WPF 的库使用新项目格式要求对新的格式比较熟悉,所以请直接卸载项目,编辑一下项目文件,填入下面的代码 224 | 225 | ``` 226 | 227 | 228 | $(MSBuildToolsPath)\Microsoft.CSharp.targets 229 | net45; 230 | Library 231 | WpfUI 232 | WpfUI 233 | true 234 | 235 | 236 | $(DefineConstants);WPF 237 | 238 | 239 | 240 | 241 | %(Filename) 242 | 243 | 244 | Designer 245 | MSBuild:Compile 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | all 268 | runtime; build; native; contentfiles; analyzers 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | Code 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | MSBuild:Compile 300 | 301 | 302 | 303 | ``` 304 | 305 | 请根据实际的项目更改 AssemblyName 的值 306 | 307 | 制作源代码包的方式和控制台的相同,只需要在 Nuget 安装 SourceYard 就可以,同样打开属性,和控制台一样 308 | 309 | 310 | 311 | ![](http://image.acmx.xyz/lindexi%2F201812914469889) 312 | 313 | 现在右击重新编译,就可以在输出文件夹找到输出的两个 Nuget 包 314 | 315 | 再创建一个 WPF 程序,通过设置本地的 Nuget 包的文件夹,安装源代码包,然后在界面使用刚才的用户控件,运行就可以发现成功使用了用户控件 316 | 317 | 打开 WPF 程序的输出文件夹,可以发现这个文件夹里面只有一个 exe 源代码已经放在 exe 里 318 | 319 | ## 调试 320 | 321 | 在将项目制作 Nuget 包的时候,就有小伙伴吐槽在开发的时候,如果使用 Nuget 安装,很难进行调试,很难在 dll 里面添加断点,同时在调试的时候修改代码 322 | 323 | 但是在使用 SourceYard 调试的时候,安装 Nuget 的库和调试本地的引用的代码是完全一样的,就使用上面的控制台调试 324 | 325 | 例如需要无论用户输出的是什么返回的都是 林德熙是逗比 326 | 327 | 细心的小伙伴会发现安装 SourceYard 之后,在项目会出现一个文件夹是 SourceProject 里面就有一个文件 TheLib.Source.SourceProject.props 打开这个文件可以看到下面的内容 328 | 329 | ``` 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 340 | 341 | 342 | 345 | 346 | 347 | 348 | ``` 349 | 350 | 这个文件里面有一些代码暂时无法使用,需要先做设置,首先设置 TheLibSourceFolder 这里表示源代码包的原始项目的文件夹,如 TheLib 的文件夹是 `C:\lindexi\SourceYard\TheLib` 请小心设置路径 351 | 352 | 353 | 354 | ![](http://image.acmx.xyz/lindexi%2F2018129145744939) 355 | 356 | 然后取消除了中文的注释,请看代码 357 | 358 | ``` 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | $(DefineConstants);TheLibSOURCE_REFERENCE 368 | 369 | 370 | 371 | 372 | C:\lindexi\SourceYard\TheLib 373 | 374 | 375 | 376 | 377 | ``` 378 | 379 | 此时通过 ctrl+点击的方式可以进入 Money 文件,这时可以进行调试 380 | 381 | 382 | 383 | ![](http://image.acmx.xyz/lindexi%2F2018129151516104) 384 | 385 | 此时在这个函数下面返回林德熙是逗比 386 | 387 | 388 | 389 | ![](http://image.acmx.xyz/lindexi%2F2018129151516104) 390 | 391 | 按 F5 运行,可以看到输出的是 林德熙是逗比 也就是源代码已经修改 392 | 393 | 打开 TheLib 的 Money.cs 文件可以发现里面的文件也同时被修改,也就是这个文件被两个项目引用,通过这个方法就和将项目引用的方式那样调试解决 dll 难以断点和修改代码 394 | 395 | 如果不设置 TheLibSourceFolder 路径,也是可以调试文件,同样也可以在调试的时候修改代码,但是这时的代码是无法上传的,也就是只能在本地的缓存使用,在清空缓存之后,对代码的修改将会找不到 396 | 397 | 因为 SourceYard 还在开发过程,代码开放在 [github](https://github.com/dotnet-campus/SourceYard ) 欢迎小伙伴贡献 398 | 399 | 知识共享许可协议
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。欢迎转载、使用、重新发布,但务必保留文章署名[林德熙](http://blog.csdn.net/lindexi_gd)(包含链接:http://blog.csdn.net/lindexi_gd ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我[联系](mailto:lindexi_gd@163.com)。 400 | -------------------------------------------------------------------------------- /sample/Sample.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.136 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{8EA1AC0A-75EA-4D9F-9D89-4AC8886EC9D0}" 7 | ProjectSection(SolutionItems) = preProject 8 | build\Version.props = build\Version.props 9 | EndProjectSection 10 | EndProject 11 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "App", "App", "{F759FC49-18C9-4AA6-8D6B-7D151777A0E5}" 12 | EndProject 13 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppUsingDll", "App\AppUsingDll\AppUsingDll.csproj", "{457DCF08-D0FB-456A-A50C-663C991CFBC9}" 14 | EndProject 15 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TheLib", "App\TheLib\TheLib.csproj", "{AC631952-4B75-437B-9C9A-7A2D9FFD2712}" 16 | EndProject 17 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppUsingSource", "App\AppUsingSource\AppUsingSource.csproj", "{E5BCA9B4-10EA-46A5-A252-86492962DBF0}" 18 | EndProject 19 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WPF", "WPF", "{D44D4292-E398-4104-B15A-97DBFEFD2D88}" 20 | EndProject 21 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfApp", "WPF\WpfApp\WpfApp.csproj", "{F2A2F01B-8454-40DF-9E6B-A9DB4DFC58D8}" 22 | EndProject 23 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfUI", "WPF\WpfUI\WpfUI.csproj", "{4CE66408-1FBD-45FC-9377-397456E877F1}" 24 | EndProject 25 | Global 26 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 27 | Debug|Any CPU = Debug|Any CPU 28 | Release|Any CPU = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {457DCF08-D0FB-456A-A50C-663C991CFBC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {457DCF08-D0FB-456A-A50C-663C991CFBC9}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {457DCF08-D0FB-456A-A50C-663C991CFBC9}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {457DCF08-D0FB-456A-A50C-663C991CFBC9}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {AC631952-4B75-437B-9C9A-7A2D9FFD2712}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {AC631952-4B75-437B-9C9A-7A2D9FFD2712}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {AC631952-4B75-437B-9C9A-7A2D9FFD2712}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {AC631952-4B75-437B-9C9A-7A2D9FFD2712}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {E5BCA9B4-10EA-46A5-A252-86492962DBF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {E5BCA9B4-10EA-46A5-A252-86492962DBF0}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {E5BCA9B4-10EA-46A5-A252-86492962DBF0}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {E5BCA9B4-10EA-46A5-A252-86492962DBF0}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {F2A2F01B-8454-40DF-9E6B-A9DB4DFC58D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {F2A2F01B-8454-40DF-9E6B-A9DB4DFC58D8}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {F2A2F01B-8454-40DF-9E6B-A9DB4DFC58D8}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {F2A2F01B-8454-40DF-9E6B-A9DB4DFC58D8}.Release|Any CPU.Build.0 = Release|Any CPU 47 | {4CE66408-1FBD-45FC-9377-397456E877F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 48 | {4CE66408-1FBD-45FC-9377-397456E877F1}.Debug|Any CPU.Build.0 = Debug|Any CPU 49 | {4CE66408-1FBD-45FC-9377-397456E877F1}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {4CE66408-1FBD-45FC-9377-397456E877F1}.Release|Any CPU.Build.0 = Release|Any CPU 51 | EndGlobalSection 52 | GlobalSection(SolutionProperties) = preSolution 53 | HideSolutionNode = FALSE 54 | EndGlobalSection 55 | GlobalSection(NestedProjects) = preSolution 56 | {457DCF08-D0FB-456A-A50C-663C991CFBC9} = {F759FC49-18C9-4AA6-8D6B-7D151777A0E5} 57 | {AC631952-4B75-437B-9C9A-7A2D9FFD2712} = {F759FC49-18C9-4AA6-8D6B-7D151777A0E5} 58 | {E5BCA9B4-10EA-46A5-A252-86492962DBF0} = {F759FC49-18C9-4AA6-8D6B-7D151777A0E5} 59 | {F2A2F01B-8454-40DF-9E6B-A9DB4DFC58D8} = {D44D4292-E398-4104-B15A-97DBFEFD2D88} 60 | {4CE66408-1FBD-45FC-9377-397456E877F1} = {D44D4292-E398-4104-B15A-97DBFEFD2D88} 61 | EndGlobalSection 62 | GlobalSection(ExtensibilityGlobals) = postSolution 63 | SolutionGuid = {D994A34A-AF17-461B-B5C4-0DB24A11BFFD} 64 | EndGlobalSection 65 | EndGlobal 66 | -------------------------------------------------------------------------------- /sample/WPF/WpfApp/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sample/WPF/WpfApp/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace WpfApp 10 | { 11 | /// 12 | /// App.xaml 的交互逻辑 13 | /// 14 | public partial class App : Application 15 | { 16 | [STAThread] 17 | private static void Main(string[] args) 18 | { 19 | var app = new App(); 20 | app.InitializeComponent(); 21 | app.Run(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/WPF/WpfApp/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /sample/WPF/WpfApp/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace WpfApp 17 | { 18 | /// 19 | /// MainWindow.xaml 的交互逻辑 20 | /// 21 | public partial class MainWindow : Window 22 | { 23 | public MainWindow() 24 | { 25 | InitializeComponent(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/WPF/WpfApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using System.Windows; 3 | 4 | // 将 ComVisible 设置为 false 会使此程序集中的类型 5 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 6 | //请将此类型的 ComVisible 特性设置为 true。 7 | [assembly: ComVisible(false)] 8 | 9 | [assembly: ThemeInfo( 10 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置 11 | //(未在页面中找到资源时使用, 12 | //或应用程序资源字典中找到时使用) 13 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 14 | //(未在页面中找到资源时使用, 15 | //、应用程序或任何主题专用资源字典中找到时使用) 16 | )] -------------------------------------------------------------------------------- /sample/WPF/WpfApp/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace WpfApp.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfApp.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 覆盖当前线程的 CurrentUICulture 属性 56 | /// 使用此强类型的资源类的资源查找。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /sample/WPF/WpfApp/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /sample/WPF/WpfApp/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace WpfApp.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sample/WPF/WpfApp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/WPF/WpfApp/SourceProject/.gitignore: -------------------------------------------------------------------------------- 1 | *.Source.SourceProject.props -------------------------------------------------------------------------------- /sample/WPF/WpfApp/WpfApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildToolsPath)\Microsoft.CSharp.targets 5 | net45; 6 | WinExe 7 | WpfApp 8 | WpfApp 9 | 10 | 11 | 12 | 13 | %(Filename) 14 | 15 | 16 | Designer 17 | MSBuild:Compile 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /sample/WPF/WpfUI/InterestingControl.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | 10 |